stanfordnlp/CoreNLP · error · IllegalArgumentException
Unknown argument " + args[argIndex]
Error message
Unknown argument " + args[argIndex]
What it means
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.
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
Example fix
// before java edu.stanford.nlp.sentiment.ExternalEvaluate -goldPath gold.txt -predic file.txt // after java edu.stanford.nlp.sentiment.ExternalEvaluate -goldPath gold.txt -predicted preds.txt
Defensive patterns
Strategy: validation
Validate before calling
Set<String> valid = new HashSet<>(Arrays.asList("-gold","-predicted","-annotations","-model","-saveModel","-testPath"));
for (String a : args) if (a.startsWith("-") && !valid.contains(a.toLowerCase())) throw new IllegalArgumentException("Unknown argument " + a); Try / catch
try { ExternalEvaluate.main(args); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("Unknown argument")) { printUsageAndExit(); } else { throw e; } } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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
- TaggedFileRecord argument
- -threads [number]: was not given a valid number:
- Unknown argument:
- Unknown argument " + args[argIndex]
- Unknown argument " + args[argIndex]
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/b1db8a55f141c9c5.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/sentiment/ExternalEvaluate.java:72
*
* For example <br>
* {@code java edu.stanford.nlp.sentiment.ExternalEvaluate annotatedTrees.txt predictedTrees.txt }
*/
public static void main(String[] args) {
RNNOptions curOptions = new RNNOptions();
String goldPath = null;
String predictedPath = null;
for (int argIndex = 0; argIndex < args.length;) {
if (args[argIndex].equalsIgnoreCase("-gold")) {
goldPath = args[argIndex + 1];
argIndex += 2;
} else if (args[argIndex].equalsIgnoreCase("-predicted")) {
predictedPath = args[argIndex + 1];
argIndex += 2;
} else {
int newArgIndex = curOptions.setOption(args, argIndex);
if (newArgIndex == argIndex) {
throw new IllegalArgumentException("Unknown argument " + args[argIndex]);
}
argIndex = newArgIndex;
}
}
if (goldPath == null) {
log.info("goldPath not set. Exit.");
System.exit(-1);
}
if (predictedPath == null) {
log.info("predictedPath not set. Exit.");
System.exit(-1);
}
// filterUnknown not supported because I'd need to know which sentences
// are removed to remove them from predicted
List<Tree> goldTrees = SentimentUtils.readTreesWithGoldLabels(goldPath);
List<Tree> predictedTrees = SentimentUtils.readTreesWithPredictedLabels(predictedPath);
ExternalEvaluate evaluator = new ExternalEvaluate(curOptions, predictedTrees);View on GitHub (pinned to 1b7edd19c4)