{"record":{"id":"bfd9acbc9fe43209","repo":"stanfordnlp/CoreNLP","slug":"cannot-process-tree-tree","errorCode":null,"errorMessage":"Cannot process tree:\n<tree>","messagePattern":"Cannot process tree:\n<tree>","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/GrammaticalStructure.java","lineNumber":186,"sourceCode":"    if (transformer != null) {\n      Tree transformed = transformer.transformTree(treeGraph);\n      if (!(transformed instanceof TreeGraphNode)) {\n        throw new RuntimeException(\"Transformer did not change TreeGraphNode into another TreeGraphNode: \" + transformer);\n      }\n      this.root = (TreeGraphNode) transformed;\n    } else {\n      this.root = treeGraph;\n    }\n    //System.out.println(this.root.toPrettyString(2));\n    indexNodes(this.root);\n    // add head word and tag to phrase nodes\n    if (hf == null) {\n      throw new AssertionError(\"Cannot use null HeadFinder\");\n    }\n    try {\n      root.percolateHeads(hf);\n    } catch (IllegalArgumentException e) {\n      throw new IllegalArgumentException(\"Cannot process tree:\\n\" + t, e);\n    }\n    if (root.value() == null) {\n      root.setValue(\"ROOT\");  // todo: cdm: it doesn't seem like this line should be here\n    }\n    // add dependencies, using heads\n    this.puncFilter = puncFilter;\n    this.tagFilter = tagFilter;\n    // NoPunctFilter puncDepFilter = new NoPunctFilter(puncFilter);\n    NoPunctTypedDependencyFilter puncTypedDepFilter = new NoPunctTypedDependencyFilter(puncFilter, tagFilter);\n\n    DirectedMultiGraph<TreeGraphNode, GrammaticalRelation> basicGraph = new DirectedMultiGraph<>();\n    DirectedMultiGraph<TreeGraphNode, GrammaticalRelation> completeGraph = new DirectedMultiGraph<>();\n\n    // analyze the root (and its descendants, recursively)\n    if (relationsLock != null) {\n      relationsLock.lock();\n    }\n    try {","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/GrammaticalStructure.java#L168-L204","documentation":"After building the tree graph, GrammaticalStructure calls root.percolateHeads(headFinder). If the HeadFinder cannot assign heads (it throws IllegalArgumentException because no head can be determined for some node, e.g. unknown category labels), the constructor rethrows with 'Cannot process tree:' plus the tree's string form and the original cause. It means the tree's structure or labels are incompatible with the supplied head finder.","triggerScenarios":"Constructing a GrammaticalStructure from a tree whose node values/categories the HeadFinder doesn't recognize (e.g. a UniversalDependencies-ish or treebank-mismatched tree); passing a HeadFinder for the wrong annotation scheme (e.g. Chinese head finder on an English tree); a tree with a node that has no children and no resolvable head.","commonSituations":"Feeding parser output from one grammar into a dependency converter tuned for another; manually built trees missing ROOT or POS structure; mixing UniversalSemanticHeadFinder with non-universal trees.","solutions":["Inspect the wrapped IllegalArgumentException cause and the printed tree to find the node whose head could not be percolated","Use the HeadFinder matching the tree's annotation scheme (e.g. UniversalSemanticHeadFinder for universal trees)","Ensure the tree is fully bracketed with POS tags and a ROOT node (run through a TreeNormalizer/TreeBank processing first)","Fix missing or malformed category labels on the offending nodes"],"exampleFix":"// before\nGrammaticalStructure gs = new EnglishGrammaticalStructure(tree, puncFilter, new ChineseHeadFinder(), ...);\n// after\nGrammaticalStructure gs = new EnglishGrammaticalStructure(tree, puncFilter, new UniversalSemanticHeadFinder(), ...);","handlingStrategy":"try-catch","validationCode":"// verify head finder compatibility before building\nif (tree.value() == null || tree.value().isEmpty())\n    throw new IllegalArgumentException(\"Tree lacks ROOT value\");\nfor (Tree t : tree) if (t.isLeaf() && (t.value() == null || t.value().isEmpty()))\n    throw new IllegalArgumentException(\"Tree has unlabeled leaf\");","typeGuard":null,"tryCatchPattern":"try {\n    GrammaticalStructure gs = new EnglishGrammaticalStructure(t, puncFilter, hf, null);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Cannot process tree:\")) {\n        // inspect e.getCause() and the printed tree; retry with correct HeadFinder\n    } else throw e;\n}","preventionTips":["Match HeadFinder to the tree's annotation scheme (e.g. UniversalSemanticHeadFinder for universal trees)","Ensure trees have POS tags and a ROOT node before dependency conversion","Print/inspect the offending tree included in the message","Test pipeline parser->dependency converter on representative trees"],"tags":["java","head-finder","parse-tree","dependency-parsing"],"backgroundTag":"invalid-argument-value","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"}