stanfordnlp/CoreNLP · error · IllegalArgumentException
Use only one of -sentences or -useLabelKeys
Error message
Use only one of -sentences or -useLabelKeys
What it means
The two input modes are mutually exclusive: -sentences parses fresh sentences while -useLabelKeys reads labels directly from existing trees. If both are supplied, main throws IllegalArgumentException("Use only one of -sentences or -useLabelKeys") to prevent ambiguous behavior.
Solutions
- Remove -sentences or -useLabelKeys so only one input mode is specified
- If label keys are wanted, drop the sentences file argument; if parsing sentences, drop -useLabelKeys
- Audit wrapper scripts for statically included flags
Example fix
// before // java ParseAndSetLabels -sentences in.txt -useLabelKeys -output o.txt ... // after // java ParseAndSetLabels -useLabelKeys -output o.txt ...
Defensive patterns
Strategy: validation
Validate before calling
java.util.List<String> a = java.util.Arrays.asList(args);
if (a.contains("-sentences") && a.contains("-useLabelKeys")) throw new IllegalArgumentException("only one of -sentences / -useLabelKeys allowed"); Try / catch
try {
ParseAndSetLabels.main(args);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("Use only one of")) System.err.println("Remove either -sentences or -useLabelKeys");
throw e;
} Prevention
- Treat the two flags as an XOR in wrapper scripts
- Clean stale flags when reusing command templates
- Add mutual-exclusion checks to launch scripts
When it happens
Trigger: Running main with both -sentences <file> and -useLabelKeys set (e.g. left over from a previous command template plus a newly added -sentences flag).
Common situations: Accumulated flags in shell scripts from copy-pasting examples; wrappers that always pass -useLabelKeys; switching input modes without removing the old flag.
Related errors
- args: treebankPath trainNums testNums
- Cannot find or open + sentFileName
- 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…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/f216f06bcabc714b.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/tools/ParseAndSetLabels.java:246
} else if (args[argIndex].equalsIgnoreCase("-useLabelKeys")) {
useLabelKeys = true;
argIndex += 1;
} else if (args[argIndex].equalsIgnoreCase("-nouseLabelKeys")) {
useLabelKeys = false;
argIndex += 1;
} else {
throw new IllegalArgumentException("Unknown argument " + args[argIndex]);
}
}
if (outputFile == null) {
throw new IllegalArgumentException("-output is required");
}
if (sentencesFile == null && !useLabelKeys) {
throw new IllegalArgumentException("-sentences or -useLabelKeys is required");
}
if (sentencesFile != null && useLabelKeys) {
throw new IllegalArgumentException("Use only one of -sentences or -useLabelKeys");
}
if (labelsFile == null) {
throw new IllegalArgumentException("-labels is required");
}
ParserGrammar parser = loadParser(parserFile, taggerFile);
TreeBinarizer binarizer = null;
if (binarize) {
binarizer = TreeBinarizer.simpleTreeBinarizer(parser.getTLPParams().headFinder(), parser.treebankLanguagePack());
}
Map<String, String> labelMap = readLabelMap(labelsFile, separator, remapLabels);
List<String> sentences;
if (sentencesFile != null) {
sentences = readSentences(sentencesFile);
} else {View on GitHub (pinned to 1b7edd19c4)