stanfordnlp/CoreNLP · error · java.lang.IllegalArgumentException
Need to supply a treebank with -treebank
Error message
Need to supply a treebank with -treebank
What it means
CacheParseHypotheses.main throws IllegalArgumentException when the parsed treebank list is empty, meaning no -treebank argument was given. The tool needs source trees to generate hypothesis trees for, so it cannot proceed without one. This is the third mandatory-argument check in main.
Solutions
- Add -treebank /path/to/treebank (e.g. a Penn Treebank file) to the command line
- Verify the flag spelling is exactly -treebank
- Confirm the treebank path exists and is readable
Example fix
// before java edu.stanford.nlp.parser.dvparser.CacheParseHypotheses -model parser.ser.gz -output out.txt.gz // after java edu.stanford.nlp.parser.dvparser.CacheParseHypotheses -model parser.ser.gz -output out.txt.gz -treebank wsj-train.txt
Defensive patterns
Strategy: validation
Validate before calling
List<String> args = Arrays.asList(cmdArgs);
if (!args.contains("-treebank")) {
throw new IllegalArgumentException("CacheParseHypotheses requires -treebank <path>");
} Try / catch
try {
CacheParseHypotheses.main(args);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("-treebank")) {
System.err.println("Usage: add -treebank /path/to/treebank.txt");
}
} Prevention
- Always pass -treebank with a real treebank file path
- Check file existence and readability before invocation
- Remember treebank paths can include start/stop index arguments
When it happens
Trigger: Running CacheParseHypotheses with -model and -output but no -treebank flag, or passing -treebank with no following path so the collection ends up empty.
Common situations: Omitting the treebank path in scripted invocations; pointing at a flag-only argument; misunderstanding that the treebank must be supplied as a file path (optionally with file ranges like file.txt 0 100).
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Need to supply a parser model with -model
- Need to supply an output filename with -output
- Found an argument -baseModels with no actual models named
- Need to specify -model to load an already prepared…
- Please specify either -file, -fileList or -stdin
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/d2637398cffc82d7.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/dvparser/CacheParseHypotheses.java:239
treebanks.add(treebankDescription);
continue;
}
if (args[argIndex].equalsIgnoreCase("-numThreads")) {
numThreads = Integer.parseInt(args[argIndex + 1]);
argIndex += 2;
continue;
}
throw new IllegalArgumentException("Unknown argument " + args[argIndex]);
}
if (parserModel == null) {
throw new IllegalArgumentException("Need to supply a parser model with -model");
}
if (output == null) {
throw new IllegalArgumentException("Need to supply an output filename with -output");
}
if (treebanks.isEmpty()) {
throw new IllegalArgumentException("Need to supply a treebank with -treebank");
}
log.info("Writing output to " + output);
log.info("Loading parser model " + parserModel);
log.info("Writing " + dvKBest + " hypothesis trees for each tree");
LexicalizedParser parser = LexicalizedParser.loadModel(parserModel, "-dvKBest", Integer.toString(dvKBest));
CacheParseHypotheses cacher = new CacheParseHypotheses(parser);
TreeTransformer transformer = DVParser.buildTrainTransformer(parser.getOp());
List<Tree> sentences = new ArrayList<>();
for (Pair<String, FileFilter> description : treebanks) {
log.info("Reading trees from " + description.first);
Treebank treebank = parser.getOp().tlpParams.memoryTreebank();
treebank.loadPath(description.first, description.second);
treebank = treebank.transform(transformer);
sentences.addAll(treebank);
}View on GitHub (pinned to 1b7edd19c4)