{"record":{"id":"3c0d0dd9e42c370f","repo":"stanfordnlp/CoreNLP","slug":"unknown-missinglabels-mode-missing","errorCode":null,"errorMessage":"Unknown MissingLabels mode \" + missing","messagePattern":"Unknown MissingLabels mode \" \\+ missing","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/tools/ParseAndSetLabels.java","lineNumber":83,"sourceCode":"      return;\n    }\n    String text = SentenceUtils.listToString(tree.yield());\n    String label = labelMap.get(text);\n    if (label != null) {\n      tree.label().setValue(label);\n    } else {\n      switch (missing) {\n      case FAIL:\n        throw new RuntimeException(\"No label for '\" + text + \"'\");\n      case DEFAULT:\n        tree.label().setValue(defaultLabel);\n        unknowns.add(text);\n        break;\n      case KEEP_ORIGINAL:\n        // do nothing\n        break;\n      default:\n        throw new IllegalArgumentException(\"Unknown MissingLabels mode \" + missing);\n      }\n    }\n    for (Tree child : tree.children()) {\n      setLabels(child, labelMap, missing, defaultLabel, unknowns);\n    }\n  }\n\n  public static Set<String> setLabels(List<Tree> trees, Map<String, String> labelMap,\n                                      MissingLabels missing, String defaultLabel) {\n    logger.info(\"Setting labels\");\n\n    Set<String> unknowns = new HashSet<>();\n\n    for (Tree tree : trees) {\n      setLabels(tree, labelMap, missing, defaultLabel, unknowns);\n    }\n\n    return unknowns;","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/tools/ParseAndSetLabels.java#L65-L101","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nsetLabels(tree, labelMap, missing, defaultLabel, unknowns); // missing == null\n// after\nif (missing == null) missing = MissingLabels.FAIL;\nsetLabels(tree, labelMap, missing, defaultLabel, unknowns);","handlingStrategy":"type-guard","validationCode":"if (missing == null) missing = MissingLabels.FAIL;\n// ensure it is one of the enum constants\nMissingLabels.valueOf(missing.name());","typeGuard":"static boolean isValidMissing(MissingLabels m) {\n  return m == MissingLabels.FAIL || m == MissingLabels.DEFAULT || m == MissingLabels.KEEP_ORIGINAL;\n}","tryCatchPattern":"try {\n  setLabels(tree, labelMap, missing, defaultLabel, unknowns);\n} catch (IllegalArgumentException e) {\n  if (e.getMessage().startsWith(\"Unknown MissingLabels\")) missing = MissingLabels.FAIL;\n  else throw e;\n}","preventionTips":["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"],"tags":["java","enum","argument-validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}