stanfordnlp/CoreNLP · error · IllegalArgumentException
Need to specify -testTreebank
Error message
Need to specify -testTreebank
What it means
FindNearestNeighbors needs a test treebank of gold trees to parse and query for nearest neighbors. When -testTreebank is not supplied, main() throws this IllegalArgumentException. It is a required-input check performed before model loading.
Solutions
- Pass -testTreebank <path-to-treebank-file> pointing at gold trees
- Ensure the path exists and is readable (the error fires before the file is opened, so fix the flag first)
- Provide all three required flags together: -model, -testTreebank, -output
Example fix
// before -Dmodel=dvparser.ser.gz ... FindNearestNeighbors -output out.txt // after FindNearestNeighbors -model dvparser.ser.gz -testTreebank test.gold -output out.txt
Defensive patterns
Strategy: validation
Validate before calling
if (!Arrays.asList(args).contains("-testTreebank")) {
throw new IllegalArgumentException("FindNearestNeighbors requires -testTreebank <goldTrees>");
} Try / catch
try {
FindNearestNeighbors.main(args);
} catch (IllegalArgumentException e) {
System.err.println("Missing required option: " + e.getMessage());
} Prevention
- Keep a canonical command template with -model, -testTreebank, -output
- Verify the treebank file exists before running
- Avoid flag-name typos by copying from working examples
When it happens
Trigger: Running FindNearestNeighbors.main() with -model and -output set but no -testTreebank flag, leaving testTreebankPath null.
Common situations: Omitting the treebank when experimenting with small inputs; assuming a default evaluation set; typo-ing the flag (e.g. -test_treebank).
Understand the failure class
Background: "Must pass :limit option" / "Missing required option" — required option errors explained — this error's family across 41 libraries.
Related errors
- Error: No dest file provided in properties or via command…
- Error: No training file provided in properties or via…
- Error: No training file provided in properties or via…
- Error: -train option must have treebankPath as first…
- -labels is required
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/63b8cb0322229d63.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/dvparser/FindNearestNeighbors.java:91
argIndex += 2;
} else if (args[argIndex].equalsIgnoreCase("-testTreebank")) {
Pair<String, FileFilter> treebankDescription = ArgUtils.getTreebankDescription(args, argIndex, "-testTreebank");
argIndex = argIndex + ArgUtils.numSubArgs(args, argIndex) + 1;
testTreebankPath = treebankDescription.first();
testTreebankFilter = treebankDescription.second();
} else if (args[argIndex].equalsIgnoreCase("-output")) {
outputPath = args[argIndex + 1];
argIndex += 2;
} else {
unusedArgs.add(args[argIndex++]);
}
}
if (modelPath == null) {
throw new IllegalArgumentException("Need to specify -model");
}
if (testTreebankPath == null) {
throw new IllegalArgumentException("Need to specify -testTreebank");
}
if (outputPath == null) {
throw new IllegalArgumentException("Need to specify -output");
}
String[] newArgs = unusedArgs.toArray(new String[unusedArgs.size()]);
LexicalizedParser lexparser = LexicalizedParser.loadModel(modelPath, newArgs);
Treebank testTreebank = null;
if (testTreebankPath != null) {
log.info("Reading in trees from " + testTreebankPath);
if (testTreebankFilter != null) {
log.info("Filtering on " + testTreebankFilter);
}
testTreebank = lexparser.getOp().tlpParams.memoryTreebank();;
testTreebank.loadPath(testTreebankPath, testTreebankFilter);
log.info("Read in " + testTreebank.size() + " trees for testing");View on GitHub (pinned to 1b7edd19c4)