stanfordnlp/CoreNLP · error · IllegalArgumentException
Unknown MissingLabels mode " + missing
Error message
Unknown MissingLabels mode " + missing
What it means
After a label lookup fails, setLabels switches on the configured MissingLabels policy (FAIL, DEFAULT, KEEP_ORIGINAL); any other enum value reaches the default branch and throws IllegalArgumentException naming the unknown mode. This is an internal-guard against an invalid MissingLabels enum value.
Solutions
- Use only the defined MissingLabels enum constants: FAIL, DEFAULT, KEEP_ORIGINAL
- Fix code passing null or an invalid value into setLabels
- Align CoreNLP jar versions across the classpath to avoid stale enum constants
- Validate/parse the missing-labels option through the enum's valueOf with error handling
Example fix
// before setLabels(tree, labelMap, missing, defaultLabel, unknowns); // missing == null // after if (missing == null) missing = MissingLabels.FAIL; setLabels(tree, labelMap, missing, defaultLabel, unknowns);
Defensive patterns
Strategy: type-guard
Validate before calling
if (missing == null) missing = MissingLabels.FAIL; // ensure it is one of the enum constants MissingLabels.valueOf(missing.name());
Type guard
static boolean isValidMissing(MissingLabels m) {
return m == MissingLabels.FAIL || m == MissingLabels.DEFAULT || m == MissingLabels.KEEP_ORIGINAL;
} Try / catch
try {
setLabels(tree, labelMap, missing, defaultLabel, unknowns);
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("Unknown MissingLabels")) missing = MissingLabels.FAIL;
else throw e;
} Prevention
- Only construct MissingLabels via the enum constants or valueOf
- Keep all CoreNLP jars at one version on the classpath
- Never pass null for enum parameters
When it happens
Trigger: Invoking setLabels(tree, labelMap, missing, defaultLabel, unknowns) programmatically with a MissingLabels value outside the defined enum constants (e.g. null or a stale enum from an incompatible jar version).
Common situations: Reflection/config-driven construction of a MissingLabels value that no longer exists after a Stanford CoreNLP version upgrade; passing null where an enum is expected; mixing jars of different CoreNLP versions on the classpath.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Arabic does not support feature type: " + feat.toString()
- Bad arguments: " + x + " and " + lambda
- conditionalLogProbGivenFirst requires of one less than…
- conditionalLogProbGivenNext requires given one less than…
- conditionalLogProbGivenPrevious requires given one less…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/3c0d0dd9e42c370f.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/tools/ParseAndSetLabels.java:83
return;
}
String text = SentenceUtils.listToString(tree.yield());
String label = labelMap.get(text);
if (label != null) {
tree.label().setValue(label);
} else {
switch (missing) {
case FAIL:
throw new RuntimeException("No label for '" + text + "'");
case DEFAULT:
tree.label().setValue(defaultLabel);
unknowns.add(text);
break;
case KEEP_ORIGINAL:
// do nothing
break;
default:
throw new IllegalArgumentException("Unknown MissingLabels mode " + missing);
}
}
for (Tree child : tree.children()) {
setLabels(child, labelMap, missing, defaultLabel, unknowns);
}
}
public static Set<String> setLabels(List<Tree> trees, Map<String, String> labelMap,
MissingLabels missing, String defaultLabel) {
logger.info("Setting labels");
Set<String> unknowns = new HashSet<>();
for (Tree tree : trees) {
setLabels(tree, labelMap, missing, defaultLabel, unknowns);
}
return unknowns;View on GitHub (pinned to 1b7edd19c4)