languagetool-org/languagetool · error · WrongParameterNumberException

WrongParameterNumberException

Error message

WrongParameterNumberException

What it means

CommandLineParser.parseOptions() validates the raw argv array before parsing flags. It throws WrongParameterNumberException when the program is invoked with zero arguments or more than 14 arguments, because LanguageTool's command-line mode requires at least a text file (or text input) and only recognizes a bounded set of options.

Source

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

 */
package org.languagetool.commandline;

import org.languagetool.JLanguageTool;
import org.languagetool.Language;
import org.languagetool.Languages;

import java.io.File;
import java.io.PrintStream;
import java.util.Arrays;

/**
 * Parser for the command line arguments.
 */
class CommandLineParser {

  CommandLineOptions parseOptions(String[] args) {
    if (args.length < 1 || args.length > 14) {
      throw new WrongParameterNumberException();
    }
    CommandLineOptions options = new CommandLineOptions();
    for (int i = 0; i < args.length; i++) {
      if (args[i].equals("--version")) {
        options.setPrintVersion(true);
      } else if (args[i].equals("--list")) {
        options.setPrintLanguages(true);
      } else if (args[i].equals("-h") || args[i].equals("-help") || args[i].equals("--help") || args[i].equals("--?")) {
        options.setPrintUsage(true);
      } else if (args[i].equals("-adl") || args[i].equals("--autoDetect")) {    // set autoDetect flag
        options.setAutoDetect(true);
      } else if (args[i].equals("-v") || args[i].equals("--verbose")) {
        options.setVerbose(true);
      } else if (args[i].equals("--line-by-line")) {
        options.setLineByLine(true);
      } else if (args[i].equals("--enable-temp-off")) {
        options.setEnableTempOff(true);
      } else if (args[i].equals("--clean-overlapping")) {

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Pass at least one argument: the text file to check (e.g. `languagetool -l en mytext.txt`).
  2. Count your arguments; consolidate rule lists into a single comma-separated value for -d/--disable or -e/--enable to stay at or below 14 arguments.
  3. Show usage with --help (or see CommandLineParser.testUsage) to confirm the accepted argument forms.
  4. If you need more options than the cap allows, use the JLanguageTool Java API or the HTTP server instead of the CLI.

Example fix

// before
languagetool
// after
languagetool -l en myfile.txt
Defensive patterns

Strategy: validation

Validate before calling

if (args.length < 1 || args.length > 14) {
  System.err.println("Expected 1-14 arguments, got " + args.length + ". See --help.");
  System.exit(2);
}

Try / catch

try {
  CommandLineOptions opts = new CommandLineParser().parseOptions(args);
} catch (WrongParameterNumberException e) {
  System.err.println("Invalid argument count; pass the text file and at most 14 arguments. Use --help.");
}

Prevention

When it happens

Trigger: Running the `languagetool` launcher with no arguments at all (args.length == 0), or passing more than 14 arguments (e.g. many enabled/disabled rules combined with multiple flags pushing the count over the limit). Called from main() for every CLI invocation.

Common situations: New users running `java -cp ... org.languagetool.commandline.Main` without a file argument; CI scripts that lost their arguments due to quoting bugs; scripts accumulating many --disable/--enable rule lists until the 14-argument cap is exceeded.

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/3c44d74921639b94. Report an issue: GitHub.