languagetool-org/languagetool · error · IllegalArgumentException

Missing argument to <option> command line option.

Error message

Missing argument to <option> command line option.

What it means

checkArguments, called by parseOptions for options that take a value, verifies that another argument follows the option: if argParsingPos + 1 >= args.length there is nothing to consume, and it throws IllegalArgumentException 'Missing argument to <option> command line option.' This guards value-taking flags like --language, --encoding, --level, etc.

Source

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

            + "  --falsefriends FILE      use external false friend file to be used along with the built-in rules\n"
            + "  --bitextrules  FILE      use external bitext XML rule file (useful only in bitext mode)\n"
            + "  --languagemodel DIR      a directory with e.g. 'en' sub directory (i.e. a language code) that contains\n"
            + "                           '1grams'...'3grams' sub directories with Lucene indexes with\n"
            + "                           ngram occurrence counts; activates the confusion rule if supported;\n"
            + "                           see https://dev.languagetool.org/finding-errors-using-n-gram-data\n"
            + "  --fasttextmodel FILE     fasttext language detection model (optional), see https://fasttext.cc/docs/en/language-identification.html\n"
            + "  --fasttextbinary FILE    fasttext executable (optional), see https://fasttext.cc/docs/en/support.html\n"
            + "  --xmlfilter              [deprecated] remove XML/HTML elements from input before checking\n"
            + "  --line-by-line           work on file line by line (for development, e.g. inside an IDE)\n"
            + "  --enable-temp-off        enable all temp_off rules (for testing and development)\n"
            + "  --clean-overlapping      clean overlapping matches (show only the highest priority match)\n"
            + "  --level level            enable the given level (currently only 'PICKY')"
    );
  }

  private void checkArguments(String option, int argParsingPos, String[] args) {
    if (argParsingPos + 1 >= args.length) {
      throw new IllegalArgumentException("Missing argument to " + option + " command line option.");
    }
  }

  private Language getLanguage(String userSuppliedLangCode) {
    return Languages.getLanguageForShortCode(userSuppliedLangCode);
  }

}

View on GitHub (pinned to 2e990059ce)

Solutions

  1. Supply the required value after the option (e.g. `-l en`, `--encoding utf-8`)
  2. In scripts, guard variable expansion: fail fast if the value variable is empty
  3. Check the option reference (printUsage/--help) for which flags require values

Example fix

# before (LANG_CODE empty)
languagetool --language $LANG_CODE file.txt
# after
: "${LANG_CODE:?LANG_CODE must be set}"
languagetool --language "$LANG_CODE" file.txt
Defensive patterns

Strategy: validation

Validate before calling

if (args.length >= 2 && VALUE_OPTIONS.contains(args[args.length - 2]) && args.length == 2) {
  throw new IllegalArgumentException("Option " + args[args.length - 2] + " requires a value");
}

Type guard

static boolean optionHasValue(String[] args, String option) {
  for (int i = 0; i < args.length; i++) {
    if (args[i].equals(option)) return i + 1 < args.length;
  }
  return true;
}

Try / catch

try {
  options = CommandLineParser.parseOptions(args);
} catch (IllegalArgumentException e) {
  if (e.getMessage().startsWith("Missing argument to")) {
    System.err.println(e.getMessage() + " — supply the value after the option");
    System.exit(2);
  }
  throw e;
}

Prevention

When it happens

Trigger: Ending the command line with a value-taking option, e.g. `languagetool -l` or `languagetool --encoding` with no value; also using a shell variable that expands to empty (`languagetool --language $LANG_CODE` with LANG_CODE unset).

Common situations: Unset or empty environment variables in scripts; truncating the command line when generating it programmatically; forgetting the value after moving flags around.

Understand the failure class

Background: "no subcommand specified" and "... is required": CLI errors when a required argument is missing — this error's family across 13 libraries.

Related errors


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