{"record":{"id":"f8e30d8d1c1ea2d9","repo":"languagetool-org/languagetool","slug":"unknown-file-name-expected-xml-or-bz2-xm","errorCode":null,"errorMessage":"Unknown file name, expected '.xml' or '.bz2': ${xmlDumpPath}","messagePattern":"Unknown file name, expected '\\.xml' or '\\.bz2': (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"languagetool-wikipedia/src/main/java/org/languagetool/dev/dumpcheck/WikipediaSentenceExtractor.java","lineNumber":44,"sourceCode":"import org.languagetool.Languages;\n\n/**\n * Command line tool to extract sentences from a (optionally bz2-compressed) Wikipedia XML dump.\n * @since 2.6\n */\nclass WikipediaSentenceExtractor {\n\n  private void extract(Language language, String xmlDumpPath, String outputFile) throws IOException, CompressorException {\n    try (FileInputStream fis = new FileInputStream(xmlDumpPath);\n         BufferedInputStream bis = new BufferedInputStream(fis);\n         FileWriter fw = new FileWriter(outputFile)) {\n      InputStream input;\n      if (xmlDumpPath.endsWith(\".bz2\")) {\n        input = new CompressorStreamFactory().createCompressorInputStream(bis);\n      } else if (xmlDumpPath.endsWith(\".xml\")) {\n        input = bis;\n      } else {\n        throw new IllegalArgumentException(\"Unknown file name, expected '.xml' or '.bz2': \" + xmlDumpPath);\n      }\n      int sentenceCount = 0;\n      WikipediaSentenceSource source = new WikipediaSentenceSource(input, language);\n      while (source.hasNext()) {\n        String sentence = source.next().getText();\n        if (skipSentence(sentence)) {\n          continue;\n        }\n        //System.out.println(sentence);\n        fw.write(sentence);\n        fw.write('\\n');\n        sentenceCount++;\n        if (sentenceCount % 1000 == 0) {\n          System.err.println(\"Exporting sentence #\" + sentenceCount + \"...\");\n        }\n      }\n    }\n  }","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-wikipedia/src/main/java/org/languagetool/dev/dumpcheck/WikipediaSentenceExtractor.java#L26-L62","documentation":"WikipediaSentenceExtractor.extract selects the input stream by file extension: .bz2 files are decompressed via CompressorStreamFactory, .xml files are read raw; anything else throws an IllegalArgumentException. The dump must be named with one of these two extensions because format detection is purely name-based.","triggerScenarios":"Passing a dump path ending in something other than .xml or .bz2, such as .7z, .zip, .gz, or a double extension like .xml.bz2 handled wrongly (actually .xml.bz2 ends with .bz2 so it's fine — failure cases are .gz/.zip/uncompressed-with-no-extension).","commonSituations":"Gzip-compressed dumps (.gz) which the code doesn't support; files downloaded without extension; renamed files losing the suffix.","solutions":["Rename the dump to end in .xml or .bz2","Convert other compressions (gunzip a .gz, or re-bzip2) before running","Verify the full path string has the expected suffix (watch for hidden trailing characters)"],"exampleFix":"// before\njava ... dewiki-latest-pages-articles.xml.gz\n// after\ngunzip dewiki-latest-pages-articles.xml.gz\njava ... dewiki-latest-pages-articles.xml","handlingStrategy":"validation","validationCode":"File dump = new File(path);\nString n = dump.getName();\nif (!n.endsWith(\".xml\") && !n.endsWith(\".bz2\")) {\n  throw new IllegalArgumentException(\"Dump must be .xml or .bz2: \" + n);\n}","typeGuard":null,"tryCatchPattern":"try {\n  extractor.extract(dumpPath, language);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Unknown file name\")) {\n    System.err.println(\"Rename/convert dump: \" + e.getMessage());\n  } else throw e;\n}","preventionTips":["Gunzip .gz dumps before processing","Never strip extensions when renaming downloads","Validate extension in wrapper scripts","Prefer .bz2 (natively supported) for compressed dumps"],"tags":["file-naming","unsupported-compression","cli"],"backgroundTag":"unsupported-file-extension","analyzedSha":"2e990059ce67d5e2a0f7f7ca5d31160c6709df4b","analyzedAt":"2026-09-06T09:20:17.015Z","contentChangedAt":"2026-09-06T09:20:17.015Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}