languagetool-org/languagetool · error · IllegalArgumentException

Unknown file name, expected '.xml' or '.bz2': ${xmlDumpPath}

Error message

Unknown file name, expected '.xml' or '.bz2': ${xmlDumpPath}

What it means

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.

Source

Thrown at languagetool-wikipedia/src/main/java/org/languagetool/dev/dumpcheck/WikipediaSentenceExtractor.java:44

import org.languagetool.Languages;

/**
 * Command line tool to extract sentences from a (optionally bz2-compressed) Wikipedia XML dump.
 * @since 2.6
 */
class WikipediaSentenceExtractor {

  private void extract(Language language, String xmlDumpPath, String outputFile) throws IOException, CompressorException {
    try (FileInputStream fis = new FileInputStream(xmlDumpPath);
         BufferedInputStream bis = new BufferedInputStream(fis);
         FileWriter fw = new FileWriter(outputFile)) {
      InputStream input;
      if (xmlDumpPath.endsWith(".bz2")) {
        input = new CompressorStreamFactory().createCompressorInputStream(bis);
      } else if (xmlDumpPath.endsWith(".xml")) {
        input = bis;
      } else {
        throw new IllegalArgumentException("Unknown file name, expected '.xml' or '.bz2': " + xmlDumpPath);
      }
      int sentenceCount = 0;
      WikipediaSentenceSource source = new WikipediaSentenceSource(input, language);
      while (source.hasNext()) {
        String sentence = source.next().getText();
        if (skipSentence(sentence)) {
          continue;
        }
        //System.out.println(sentence);
        fw.write(sentence);
        fw.write('\n');
        sentenceCount++;
        if (sentenceCount % 1000 == 0) {
          System.err.println("Exporting sentence #" + sentenceCount + "...");
        }
      }
    }
  }

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Rename the dump to end in .xml or .bz2
  2. Convert other compressions (gunzip a .gz, or re-bzip2) before running
  3. Verify the full path string has the expected suffix (watch for hidden trailing characters)

Example fix

// before
java ... dewiki-latest-pages-articles.xml.gz
// after
gunzip dewiki-latest-pages-articles.xml.gz
java ... dewiki-latest-pages-articles.xml
Defensive patterns

Strategy: validation

Validate before calling

File dump = new File(path);
String n = dump.getName();
if (!n.endsWith(".xml") && !n.endsWith(".bz2")) {
  throw new IllegalArgumentException("Dump must be .xml or .bz2: " + n);
}

Try / catch

try {
  extractor.extract(dumpPath, language);
} catch (IllegalArgumentException e) {
  if (e.getMessage() != null && e.getMessage().startsWith("Unknown file name")) {
    System.err.println("Rename/convert dump: " + e.getMessage());
  } else throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: Gzip-compressed dumps (.gz) which the code doesn't support; files downloaded without extension; renamed files losing the suffix.

Related errors


AI-assisted analysis of languagetool-org/languagetool@2e990059ce (2026-09-06). Data as JSON: /api/errors/f8e30d8d1c1ea2d9. Report an issue: GitHub.