stanfordnlp/CoreNLP · error · IllegalArgumentException
Unknown argument
Error message
Unknown argument
What it means
SentimentPipeline.main parses command-line arguments in a loop; when an argument matches none of the known flags, it logs, prints help, and throws IllegalArgumentException("Unknown argument " + ...). Note the message reads args[argIndex + 1], so it may show the wrong token, but the offending flag is args[argIndex].
Solutions
- Run with -help and use only the listed flags for SentimentPipeline.
- Correct the misspelled flag (e.g. -file, -fileList, -stdin, -model, -output, -input).
- Remove extra positional arguments; all inputs must go through -file, -fileList, or -stdin.
- In wrapper scripts, echo the full command and verify each flag against the -help output; note the error text may name the token after the bad flag, so check the preceding argument too.
Example fix
// before java edu.stanford.nlp.sentiment.SentimentPipeline -outputFormat scores -file in.txt // after java edu.stanford.nlp.sentiment.SentimentPipeline -output scores -file in.txt
Defensive patterns
Strategy: validation
Validate before calling
Set<String> knownFlags = new HashSet<>(Arrays.asList("-model","-file","-fileList","-stdin","-output","-input","-help","-tokenizerModel","-taggerModel"));
for (String a : args) {
if (a.startsWith("-") && !knownFlags.contains(a)) {
throw new IllegalArgumentException("Unsupported flag for SentimentPipeline: " + a);
}
} Try / catch
try {
SentimentPipeline.main(args);
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("Unknown argument")) {
// the message may show args[i+1]; re-check args[i-1] and args[i]
System.err.println("Inspect all flags against -help; bad flag likely precedes: " + e.getMessage());
} else throw e;
} Prevention
- Run -help and diff every flag in your script against it.
- Do not reuse flag sets from StanfordCoreNLP; SentimentPipeline accepts a different subset.
- Quote arguments so flags with values aren't split by the shell.
- Note the error text prints args[argIndex + 1], so the actual bad flag is one position earlier.
When it happens
Trigger: Invoking the pipeline with a flag not in its accepted set (e.g. -outputFormat instead of -output, -inputFile instead of -file), or passing a bare positional argument that isn't a recognized option.
Common situations: Copy-pasting flags from StanfordCoreNLP into SentimentPipeline (the flag sets differ); typos like -model vs -mod; scripts passing an extra positional argument; quoting mistakes that split flags.
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
- Unknown argument:
- Unknown argument " + args[argIndex]
- Unknown argument " + args[argIndex]
- Unknown output format
- Unknown format
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/dbd4b9b9630a9e43.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/sentiment/SentimentPipeline.java:298
String[] formats = args[argIndex + 1].split(",");
outputFormats = new ArrayList<>();
for (String format : formats) {
outputFormats.add(Output.valueOf(format.toUpperCase(Locale.ROOT)));
}
argIndex += 2;
} else if (args[argIndex].equalsIgnoreCase("-filterUnknown")) {
filterUnknown = true;
argIndex++;
} else if (args[argIndex].equalsIgnoreCase("-tlppClass")) {
tlppClass = args[argIndex + 1];
argIndex += 2;
} else if (args[argIndex].equalsIgnoreCase("-help")) {
help();
System.exit(0);
} else {
log.info("Unknown argument " + args[argIndex + 1]);
help();
throw new IllegalArgumentException("Unknown argument " + args[argIndex + 1]);
}
}
// We construct two pipelines. One handles tokenization, if
// necessary. The other takes tokenized sentences and converts
// them to sentiment trees.
Properties pipelineProps = new Properties();
Properties tokenizerProps = null;
if (sentimentModel != null) {
pipelineProps.setProperty("sentiment.model", sentimentModel);
}
if (parserModel != null) {
pipelineProps.setProperty("parse.model", parserModel);
}
if (inputFormat == Input.TREES) {
pipelineProps.setProperty("annotators", "binarizer, sentiment");
pipelineProps.setProperty("customAnnotatorClass.binarizer", "edu.stanford.nlp.pipeline.BinarizerAnnotator");
pipelineProps.setProperty("binarizer.tlppClass", tlppClass);View on GitHub (pinned to 1b7edd19c4)