stanfordnlp/CoreNLP · error · IllegalArgumentException
-sentences or -useLabelKeys is required
Error message
-sentences or -useLabelKeys is required
What it means
main requires a source of input trees: either -sentences (raw sentences to parse) or -useLabelKeys (read labels from the trees themselves). If neither is given, it throws IllegalArgumentException("-sentences or -useLabelKeys is required").
Solutions
- Add -sentences <file> to supply sentences to parse, or add -useLabelKeys to reuse labels from the input trees
- Do not combine -nouseLabelKeys with an absent -sentences
- Check the order of flags so a later -nouseLabelKeys doesn't negate an earlier -useLabelKeys
Example fix
// before // java ParseAndSetLabels -parser m.gz -labels l.txt -output o.txt // after // java ParseAndSetLabels -parser m.gz -labels l.txt -output o.txt -sentences input.txt
Defensive patterns
Strategy: validation
Validate before calling
java.util.List<String> a = java.util.Arrays.asList(args);
boolean hasInput = a.contains("-sentences") || a.contains("-useLabelKeys");
if (!hasInput) throw new IllegalArgumentException("need -sentences or -useLabelKeys"); Try / catch
try {
ParseAndSetLabels.main(args);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("-sentences or -useLabelKeys")) System.err.println("Specify exactly one input mode");
throw e;
} Prevention
- Decide the input mode up front in scripts
- Watch for -nouseLabelKeys negating an earlier flag
- Document the required flags in job definitions
When it happens
Trigger: Running ParseAndSetLabels.main with neither -sentences <file> nor -useLabelKeys on the command line.
Common situations: Assuming a default input mode exists; dropping -useLabelKeys when copying an older example command; accidentally negating with -nouseLabelKeys after setting -sentences.
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
- 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/b0647ea076f7e3b5.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/tools/ParseAndSetLabels.java:243
} else if (args[argIndex].equalsIgnoreCase("-nobinarize")) {
binarize = false;
argIndex += 1;
} 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;View on GitHub (pinned to 1b7edd19c4)