{"record":{"id":"7ef215c3b53c1561","repo":"stanfordnlp/CoreNLP","slug":"only-operates-on-corelabels","errorCode":null,"errorMessage":"Only operates on CoreLabels","messagePattern":"Only operates on CoreLabels","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/international/french/FrenchTreeNormalizer.java","lineNumber":74,"sourceCode":"  @Override\n  public String normalizeTerminal(String terminal) {\n    if(terminal == null) return terminal;\n\n    return super.normalizeTerminal(terminal).intern();\n  }\n\n  @Override\n  public String normalizeNonterminal(String category) {\n    return super.normalizeNonterminal(category).intern();\n  }\n\n  private static void replacePOSTag(Tree t, MorphoFeatureSpecification morpho) {\n    if (!t.isPreTerminal()) {\n      throw new IllegalArgumentException(\"Can only operate on preterminals\");\n    }\n\n    if (!(t.label() instanceof CoreLabel)) {\n      throw new IllegalArgumentException(\"Only operates on CoreLabels\");\n    }\n    CoreLabel label = (CoreLabel) t.label();\n\n    Tree child = t.children()[0];\n    if (!(child.label() instanceof CoreLabel)) {\n      throw new IllegalArgumentException(\"Only operates on CoreLabels\");\n    }\n    CoreLabel childLabel = (CoreLabel) child.label();\n\n    // Morphological Analysis\n    String morphStr = childLabel.originalText();\n    if (morphStr == null || morphStr.equals(\"\")) {\n      morphStr = label.value();\n      // POS subcategory\n      String subCat = childLabel.category();\n      if (subCat != null && subCat != \"\") {\n        morphStr += \"-\" + subCat + \"--\";\n      } else {","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/international/french/FrenchTreeNormalizer.java#L56-L92","documentation":"replacePOSTag requires the node's own label to be a CoreLabel so it can cast and mutate the POS tag. If the Tree carries a different Label implementation (e.g. StringLabel, Tag, or a custom label), the library throws IllegalArgumentException rather than doing an unsafe cast. Note the same message is also thrown for the child word node (error 1332).","triggerScenarios":"Passing a preterminal Tree whose label() is not a CoreLabel to normalizePreterminal/replacePOSTag — typically when trees were read with a non-CoreLabel TreeReader or Label factory (e.g. LabeledScoredTreeReaderFactory with StringLabel).","commonSituations":"Mixing tree sources: trees parsed with default readers then fed to the French normalizer that expects CoreLabels; constructing trees manually with new StringLabel(\"NN\"); swapping TreeReaderFactory in a pipeline but keeping the normalizer stage.","solutions":["Build/read trees with a CoreLabel factory, e.g. new LabeledScoredTreeReaderFactory() paired with CoreLabel.factory() or FrenchTreeReaderFactory which uses CoreLabels","Convert labels before normalizing: t.setLabel(CoreLabel.fromString(label.value()))","Run trees through an earlier pipeline stage (e.g. TreeToText / TreeCoreAnnotations) that guarantees CoreLabel labels","Check t.label() instanceof CoreLabel before calling the normalizer"],"exampleFix":"// before\nTree t = new LabeledScoredTreeNode(new StringLabel(\"NN\"), kids);\nnormalizer.normalizePreterminal(t, morpho); // throws\n\n// after\nCoreLabel cl = CoreLabel.fromString(\"NN\");\nTree t = new LabeledScoredTreeNode(cl, kids);\nnormalizer.normalizePreterminal(t, morpho); // ok","handlingStrategy":"validation","validationCode":"if (!(tree.label() instanceof CoreLabel))\n  throw new IllegalArgumentException(\"POS label must be CoreLabel; got \" + tree.label().getClass());","typeGuard":"static boolean hasCoreLabel(Tree t) {\n  return t.label() instanceof CoreLabel;\n}","tryCatchPattern":"try {\n  normalizer.normalizePreterminal(tree, morpho);\n} catch (IllegalArgumentException e) {\n  // convert label and retry once\n  tree.setLabel(CoreLabel.fromString(tree.label().value()));\n  normalizer.normalizePreterminal(tree, morpho);\n}","preventionTips":["Use CoreLabel.factory() as the TreeFactory label factory everywhere in the pipeline","Check reader factory configuration after any pipeline refactor","Convert labels centrally right after tree loading, not at use sites","Add an instanceof CoreLabel assertion when trees enter the French normalization stage"],"tags":["java","nlp","labels","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}