{"record":{"id":"0e669e6abefc8a1d","repo":"languagetool-org/languagetool","slug":"missing-argument-to-option-command-line-option","errorCode":null,"errorMessage":"Missing argument to <option> command line option.","messagePattern":"Missing argument to <option> command line option\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"languagetool-commandline/src/main/java/org/languagetool/commandline/CommandLineParser.java","lineNumber":233,"sourceCode":"            + \"  --falsefriends FILE      use external false friend file to be used along with the built-in rules\\n\"\n            + \"  --bitextrules  FILE      use external bitext XML rule file (useful only in bitext mode)\\n\"\n            + \"  --languagemodel DIR      a directory with e.g. 'en' sub directory (i.e. a language code) that contains\\n\"\n            + \"                           '1grams'...'3grams' sub directories with Lucene indexes with\\n\"\n            + \"                           ngram occurrence counts; activates the confusion rule if supported;\\n\"\n            + \"                           see https://dev.languagetool.org/finding-errors-using-n-gram-data\\n\"\n            + \"  --fasttextmodel FILE     fasttext language detection model (optional), see https://fasttext.cc/docs/en/language-identification.html\\n\"\n            + \"  --fasttextbinary FILE    fasttext executable (optional), see https://fasttext.cc/docs/en/support.html\\n\"\n            + \"  --xmlfilter              [deprecated] remove XML/HTML elements from input before checking\\n\"\n            + \"  --line-by-line           work on file line by line (for development, e.g. inside an IDE)\\n\"\n            + \"  --enable-temp-off        enable all temp_off rules (for testing and development)\\n\"\n            + \"  --clean-overlapping      clean overlapping matches (show only the highest priority match)\\n\"\n            + \"  --level level            enable the given level (currently only 'PICKY')\"\n    );\n  }\n\n  private void checkArguments(String option, int argParsingPos, String[] args) {\n    if (argParsingPos + 1 >= args.length) {\n      throw new IllegalArgumentException(\"Missing argument to \" + option + \" command line option.\");\n    }\n  }\n\n  private Language getLanguage(String userSuppliedLangCode) {\n    return Languages.getLanguageForShortCode(userSuppliedLangCode);\n  }\n\n}\n","sourceCodeStart":215,"sourceCodeEnd":242,"githubUrl":"https://github.com/languagetool-org/languagetool/blob/2e990059ce67d5e2a0f7f7ca5d31160c6709df4b/languagetool-commandline/src/main/java/org/languagetool/commandline/CommandLineParser.java#L215-L242","documentation":"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.","triggerScenarios":"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).","commonSituations":"Unset or empty environment variables in scripts; truncating the command line when generating it programmatically; forgetting the value after moving flags around.","solutions":["Supply the required value after the option (e.g. `-l en`, `--encoding utf-8`)","In scripts, guard variable expansion: fail fast if the value variable is empty","Check the option reference (printUsage/--help) for which flags require values"],"exampleFix":"# before (LANG_CODE empty)\nlanguagetool --language $LANG_CODE file.txt\n# after\n: \"${LANG_CODE:?LANG_CODE must be set}\"\nlanguagetool --language \"$LANG_CODE\" file.txt","handlingStrategy":"validation","validationCode":"if (args.length >= 2 && VALUE_OPTIONS.contains(args[args.length - 2]) && args.length == 2) {\n  throw new IllegalArgumentException(\"Option \" + args[args.length - 2] + \" requires a value\");\n}","typeGuard":"static boolean optionHasValue(String[] args, String option) {\n  for (int i = 0; i < args.length; i++) {\n    if (args[i].equals(option)) return i + 1 < args.length;\n  }\n  return true;\n}","tryCatchPattern":"try {\n  options = CommandLineParser.parseOptions(args);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Missing argument to\")) {\n    System.err.println(e.getMessage() + \" — supply the value after the option\");\n    System.exit(2);\n  }\n  throw e;\n}","preventionTips":["Never end a command line with a value-taking option","Use \"${VAR:?msg}\" shell expansion to catch empty variables","Double-check flag ordering after refactoring generated command lines","Ensure values with spaces are quoted so they are not dropped"],"tags":["cli","commandline","missing-argument"],"backgroundTag":"missing-cli-argument","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"}