languagetool-org/languagetool · error · UnknownParameterException

Unknown parameter: <arg>

Error message

Unknown parameter: <arg>

What it means

CommandLineParser iterates all args and every unrecognized token that is not the final filename is rejected with UnknownParameterException ('Unknown parameter: <arg>'). UnknownParameterException extends IllegalArgumentException, signaling a typo'd or unsupported CLI option.

Source

Thrown at languagetool-commandline/src/main/java/org/languagetool/commandline/CommandLineParser.java:174

          throw new IllegalArgumentException("JSON output format makes no sense for automatic application of suggestions");
        }
      } else if (args[i].equals("-p") || args[i].equals("--profile")) {
        options.setProfile(true);
        if (options.isJsonFormat()) {
          throw new IllegalArgumentException("JSON output format makes no sense for profiling");
        }
        if (options.isApplySuggestions()) {
          throw new IllegalArgumentException("Applying suggestions makes no sense for profiling");
        }
        if (options.isTaggerOnly()) {
          throw new IllegalArgumentException("Tagging makes no sense for profiling");
        }
      } else if (args[i].equals("--xmlfilter")) {
        options.setXmlFiltering(true);
      } else if (i == args.length - 1) {
        options.setFilename(args[i]);
      } else {
        throw new UnknownParameterException("Unknown parameter: " + args[i]);
      }
    }
    return options;
  }

  void printUsage() {
    printUsage(System.out);
  }

  void printUsage(PrintStream stream) {
    stream.println("Usage: java -jar languagetool-commandline.jar [OPTION]... FILE\n"
            + " FILE                      plain text file to be checked\n"
            + " Available options:\n"
            + "  -r, --recursive          work recursively on directory, not on a single file\n"
            + "  -c, --encoding ENC       character set of the input text, e.g. utf-8 or latin1\n"
            + "  -b                       assume that a single line break marks the end of a paragraph\n"
            + "  -l, --language LANG      the language code of the text, e.g. en for English, en-GB for British English\n"
            + "  --list                   print all available languages and exit\n"

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Run `languagetool --help` (or inspect printUsage) and use an exact supported flag name
  2. Check flag spelling and single-vs-double dash form
  3. Put the input filename last; options after it will be treated as unknown parameters
  4. Verify the option exists in your installed LanguageTool version

Example fix

// before
languagetool -l en --langauge en file.txt
// after
languagetool -l en file.txt
Defensive patterns

Strategy: validation

Validate before calling

for (int i = 0; i < args.length - 1; i++) {
  if (!KNOWN_OPTIONS.contains(args[i])) {
    throw new IllegalArgumentException("Unknown parameter: " + args[i]);
  }
}

Type guard

static final Set<String> KNOWN_OPTIONS = Set.of("-l","--language","-c","--encoding","-t","--tagger-only","-a","--apply-suggestions","-p","--profile","-u","--list-unknown","-r","--recursive","-b","--bitext","--twolines","--xmlfilter","--level","--disable","--enable","--version","--help");

Try / catch

try {
  options = CommandLineParser.parseOptions(args);
} catch (UnknownParameterException e) {
  System.err.println(e.getMessage() + " — run 'languagetool --help' for valid options");
  System.exit(2);
}

Prevention

When it happens

Trigger: Passing any flag not handled by parseOptions' if/else chain (e.g. `--spellcheck`, `-x`, or a misspelling like `--langauge en`) in a position that is not the last argument; also passing two filenames (the second one lands here).

Common situations: Typos in long option names; copying options from an older or newer LanguageTool version where the flag was renamed; passing options after the filename; accidentally passing two files to a tool that accepts one.

Understand the failure class

Background: "Unknown argument", "Invalid value", and "must be one of": invalid CLI argument errors explained — this error's family across 35 libraries.

Related errors


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