stanfordnlp/CoreNLP · error · IllegalArgumentException
Unknown option:
Error message
Unknown option:
What it means
Options.setOption resolves a command-line flag first via the lexparser option flags and then via the TreebankLanguagePack params; if neither consumes the flag, it throws IllegalArgumentException('Unknown option: ...'). It guarantees that every training/test flag passed to the parser is actually recognized.
Solutions
- Fix the flag spelling/name in your argument list.
- Run the parser with no arguments or consult the lexparser options documentation for valid flags for your version.
- If it is a version mismatch, check the release notes and update or remove obsolete flags.
- Pass a supported -tlpp / treebank language pack if the flag is language-pack specific.
Example fix
// before
options.setOptions(new String[]{"-maxLen", "40"});
// after
options.setOptions(new String[]{"-maxLength", "40"}); Defensive patterns
Strategy: validation
Validate before calling
Set<String> validFlags = Set.of("-maxLength","-outputFormat","-tlpp","-writeGrammarFiles");
for (int i = 0; i < args.length; i++) if (args[i].startsWith("-")) assert validFlags.contains(args[i]) : "Unknown flag: " + args[i]; Try / catch
try {
options.setOptions(flags);
} catch (IllegalArgumentException e) {
System.err.println("Bad parser flag: " + e.getMessage());
} Prevention
- Copy flags only from the documentation/source of your exact parser version.
- Run 'java -cp jar edu.stanford.nlp.parser.lexparser.LexicalizedParser' with no args to see usage.
- Add a smoke test that applies your flag list to Options.setOptions in CI.
- Keep training scripts and parser jar versions in sync.
When it happens
Trigger: Passing a flag string (e.g., via Options.setOptions, main(), or -props-style command lines) that neither setOptionFlag nor tlpParams.setOptionFlag recognizes, so the returned index equals the input index i.
Common situations: Typos in flags (e.g., '-maxLen' instead of '-maxLength'), flags removed or renamed across Stanford Parser versions, or flags that belong to a different parser package.
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
- Invalid value for -distanceBin:
- Invalid feature name '
- args: treebankPath trainNums testNums
- Bad character encoding
- Bad process cp1252
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/536e212d44675358.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/lexparser/Options.java:179
* <li> <code>-printTT</code> print the training trees in raw, annotated, and annotated+binarized form. Useful for debugging and other miscellany.
* <li> <code>-printAnnotated filename</code> use only in conjunction with -printTT. Redirects printing of annotated training trees to <code>filename</code>.
* <li> <code>-forceTags</code> when the parser is tested against a set of gold standard trees, use the tagged yield, instead of just the yield, as input.
* </ul>
*
* @param flags An array of options arguments, command-line style. E.g. {"-maxLength", "50"}.
* @param i The index in flags to start at when processing an option
* @return The index in flags of the position after the last element used in
* processing this option.
* @throws IllegalArgumentException If the current array position cannot be
* processed as a valid option
*/
public int setOption(String[] flags, int i) {
int j = setOptionFlag(flags, i);
if (j == i) {
j = tlpParams.setOptionFlag(flags, i);
}
if (j == i) {
throw new IllegalArgumentException("Unknown option: " + flags[i]);
}
return j;
}
/**
* Set an option in this object, based on a String array in the style of
* commandline flags. The option is only processed with respect to
* options directly known by the Options object.
* Some options (there are many others; see the source code):
* <ul>
* <li> <code>-maxLength n</code> set the maximum length sentence to parse (inclusively)
* <li> <code>-printTT</code> print the training trees in raw, annotated, and annotated+binarized form. Useful for debugging and other miscellany.
* <li> <code>-printAnnotated filename</code> use only in conjunction with -printTT. Redirects printing of annotated training trees to <code>filename</code>.
* <li> <code>-forceTags</code> when the parser is tested against a set of gold standard trees, use the tagged yield, instead of just the yield, as input.
* </ul>
*
* @param args An array of options arguments, command-line style. E.g. {"-maxLength", "50"}.
* @param i The index in args to start at when processing an optionView on GitHub (pinned to 1b7edd19c4)