{"record":{"id":"b1db8a55f141c9c5","repo":"stanfordnlp/CoreNLP","slug":"unknown-argument-args-argindex-b1db8a","errorCode":null,"errorMessage":"Unknown argument \" + args[argIndex]","messagePattern":"Unknown argument \" \\+ args\\[argIndex\\]","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/sentiment/ExternalEvaluate.java","lineNumber":72,"sourceCode":"   *\n   * For example <br>\n   * {@code java edu.stanford.nlp.sentiment.ExternalEvaluate annotatedTrees.txt predictedTrees.txt }\n   */\n  public static void main(String[] args) {\n    RNNOptions curOptions = new RNNOptions();\n    String goldPath = null;\n    String predictedPath = null;\n    for (int argIndex = 0; argIndex < args.length;) {\n      if (args[argIndex].equalsIgnoreCase(\"-gold\")) {\n        goldPath = args[argIndex + 1];\n        argIndex += 2;\n      } else if (args[argIndex].equalsIgnoreCase(\"-predicted\")) {\n        predictedPath = args[argIndex + 1];\n        argIndex += 2;\n      } else {\n        int newArgIndex = curOptions.setOption(args, argIndex);\n        if (newArgIndex == argIndex) {\n          throw new IllegalArgumentException(\"Unknown argument \" + args[argIndex]);\n        }\n        argIndex = newArgIndex;\n      }\n    }\n    if (goldPath == null) {\n      log.info(\"goldPath not set. Exit.\");\n      System.exit(-1);\n\n    }\n    if (predictedPath == null) {\n      log.info(\"predictedPath not set. Exit.\");\n      System.exit(-1);\n    }\n    // filterUnknown not supported because I'd need to know which sentences\n    // are removed to remove them from predicted\n    List<Tree> goldTrees = SentimentUtils.readTreesWithGoldLabels(goldPath);\n    List<Tree> predictedTrees = SentimentUtils.readTreesWithPredictedLabels(predictedPath);\n    ExternalEvaluate evaluator = new ExternalEvaluate(curOptions, predictedTrees);","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/sentiment/ExternalEvaluate.java#L54-L90","documentation":"ExternalEvaluate's CLI argument parser rejects any option it does not recognize. When neither a built-in flag nor any flag registered via curOptions (setOption) consumes the argument at argIndex, setOption returns the index unchanged and main throws IllegalArgumentException.","triggerScenarios":"Running ExternalEvaluate with a misspelled flag (e.g. '-gold' vs '-goldPath'), an option not registered in the passed Options object, or a stray positional token that the parser tries to interpret as a flag.","commonSituations":"Users copying command lines from older documentation after flag renames, forgetting a required -predicted/-gold value causing mis-parsing, or passing unknown extra args in shell scripts.","solutions":["Run with -h/help or read ExternalEvaluate javadoc to list valid flags","Check spelling of the flag against the source's accepted strings","Ensure each flag that takes a value has its value present so argIndex advances correctly","Wrap custom options via curOptions so setOption can consume them"],"exampleFix":"// before\njava edu.stanford.nlp.sentiment.ExternalEvaluate -goldPath gold.txt -predic file.txt\n// after\njava edu.stanford.nlp.sentiment.ExternalEvaluate -goldPath gold.txt -predicted preds.txt","handlingStrategy":"validation","validationCode":"Set<String> valid = new HashSet<>(Arrays.asList(\"-gold\",\"-predicted\",\"-annotations\",\"-model\",\"-saveModel\",\"-testPath\"));\nfor (String a : args) if (a.startsWith(\"-\") && !valid.contains(a.toLowerCase())) throw new IllegalArgumentException(\"Unknown argument \" + a);","typeGuard":null,"tryCatchPattern":"try { ExternalEvaluate.main(args); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith(\"Unknown argument\")) { printUsageAndExit(); } else { throw e; } }","preventionTips":["List flags with the tool's usage output before running","Keep training scripts in sync with the library version","Quote and verify flag/value pairs in shell scripts"],"tags":["cli","argument-parsing"],"backgroundTag":"invalid-cli-argument","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}