stanfordnlp/CoreNLP · error · IllegalArgumentException
Please only specify one of -file, -fileList or -stdin
Error message
Please only specify one of -file, -fileList or -stdin
What it means
main counts how many of the mutually exclusive input sources (-file, -fileList, -stdin) were specified and throws IllegalArgumentException if more than one is set. Exactly one input source must be chosen for the pipeline to know where to read trees from.
Solutions
- Remove all but one of -file, -fileList, -stdin from the command line.
- If the goal is to process multiple files, use -fileList with a file containing the list instead of multiple -file flags.
- In scripts, make the input-source selection exclusive (if/else) rather than appending flags conditionally.
- Note the companion error: specifying none of them throws 'Please specify either -file, -fileList or -stdin', so always supply exactly one.
Example fix
// before java edu.stanford.nlp.sentiment.SentimentPipeline -model model.ser.gz -file in.txt -stdin // after java edu.stanford.nlp.sentiment.SentimentPipeline -model model.ser.gz -file in.txt
Defensive patterns
Strategy: validation
Validate before calling
int sources = (file != null ? 1 : 0) + (fileList != null ? 1 : 0) + (stdin ? 1 : 0);
if (sources != 1) {
throw new IllegalArgumentException("Exactly one of -file, -fileList, -stdin must be set (got " + sources + ")");
} Try / catch
try {
SentimentPipeline.main(args);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("only specify one of")) {
System.err.println("Pass exactly one input source: -file <path>, -fileList <list>, or -stdin");
} else throw e;
} Prevention
- In scripts, build the input flags with an if/else so only one source is ever appended.
- Use -fileList for multiple files instead of combining flags.
- Validate that neither -file nor -fileList is set when stdin is piped.
- Also ensure at least one source is present, otherwise the sibling error fires.
When it happens
Trigger: Invoking SentimentPipeline with two or more of -file, -fileList, -stdin together, e.g. '-file a.txt -stdin' or '-file a.txt -fileList list.txt'.
Common situations: Scripts that default to -stdin but append -file when a path is provided; template commands that already contain one flag to which users add another; CI wrappers exporting both a file list and piping stdin.
Understand the failure class
Background: "mutually exclusive" flag errors: what "can't supply both nx and xx", "--raw is not compatible with -i" and "cannot be used with" mean, and how to fix them — this error's family across 29 libraries.
Related errors
- Unknown output format
- Unknown format
- Unknown argument
- You probably cannot read the serialized output, so printing…
- Unknown argument
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/5205a00f7f4c4725.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/sentiment/SentimentPipeline.java:336
} else {
pipelineProps.setProperty("annotators", "parse, sentiment");
pipelineProps.setProperty("parse.binaryTrees", "true");
pipelineProps.setProperty("parse.buildgraphs", "false");
pipelineProps.setProperty("enforceRequirements", "false");
tokenizerProps = new Properties();
tokenizerProps.setProperty("annotators", "tokenize, ssplit");
}
if (stdin && tokenizerProps != null) {
tokenizerProps.setProperty(StanfordCoreNLP.NEWLINE_SPLITTER_PROPERTY, "true");
}
int count = 0;
if (filename != null) count++;
if (fileList != null) count++;
if (stdin) count++;
if (count > 1) {
throw new IllegalArgumentException("Please only specify one of -file, -fileList or -stdin");
}
if (count == 0) {
throw new IllegalArgumentException("Please specify either -file, -fileList or -stdin");
}
StanfordCoreNLP tokenizer = (tokenizerProps == null) ? null : new StanfordCoreNLP(tokenizerProps);
StanfordCoreNLP pipeline = new StanfordCoreNLP(pipelineProps);
if (filename != null) {
// Process a file. The pipeline will do tokenization, which
// means it will split it into sentences as best as possible
// with the tokenizer.
List<Annotation> annotations = getAnnotations(tokenizer, inputFormat, filename, filterUnknown);
for (Annotation annotation : annotations) {
pipeline.annotate(annotation);
for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
System.out.println(sentence);View on GitHub (pinned to 1b7edd19c4)