{"record":{"id":"24f7bf12fd541f54","repo":"stanfordnlp/CoreNLP","slug":"missing-head-tree-for-a-mention","errorCode":null,"errorMessage":"Missing head tree for a mention!","messagePattern":"Missing head tree for a mention!","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/coref/data/DocumentPreprocessor.java","lineNumber":327,"sourceCode":"        m.sentNum = i;                    // sentNum\n\n        IntTuple headPosition = new IntTuple(2);\n        headPosition.set(0, i);\n        headPosition.set(1, m.headIndex);\n        doc.mentionheadPositions.put(headPosition, m);    // headPositions\n\n        m.contextParseTree = sentence.get(TreeAnnotation.class);\n//        m.sentenceWords = sentence.get(TokensAnnotation.class);\n        m.basicDependency = sentence.get(BasicDependenciesAnnotation.class);\n        m.enhancedDependency = sentence.get(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation.class);\n        if (m.enhancedDependency == null) {\n          m.enhancedDependency = sentence.get(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation.class);\n        }\n\n        // mentionSubTree (highest NP that has the same head) if constituency tree available\n        if (m.contextParseTree != null) {\n          Tree headTree = m.contextParseTree.getLeaves().get(m.headIndex);\n          if (headTree == null) { throw new RuntimeException(\"Missing head tree for a mention!\"); }\n          Tree t = headTree;\n          while ((t = t.parent(m.contextParseTree)) != null) {\n            if (t.headTerminal(headFinder) == headTree && t.value().equals(\"NP\")) {\n              m.mentionSubTree = t;\n            } else if(m.mentionSubTree != null){\n              break;\n            }\n          }\n          if (m.mentionSubTree == null) {\n            m.mentionSubTree = headTree;\n          }\n        }\n\n        m.process(dict, null, singletonPredictor);\n      }\n    }\n\n","sourceCodeStart":309,"sourceCodeEnd":345,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/coref/data/DocumentPreprocessor.java#L309-L345","documentation":"DocumentPreprocessor.fillMentionInfo throws when a mention's contextParseTree exists but the leaf at m.headIndex is null (or out of bounds), so no head tree can be located. It signals a desynchronization between the mention's head index and its parse tree.","triggerScenarios":"fillMentionInfo (via initializeMentions) computing m.contextParseTree.getLeaves().get(m.headIndex) where headIndex exceeds the leaf count — mention indices computed against a different tokenization/tree than the attached parse.","commonSituations":"Mismatched sentence segmentation between parse and mentions; custom pipeline stages that re-tokenize after parsing; corrupted or truncated parse trees; third-party parsers producing fewer leaves than tokens.","solutions":["Verify the same tokenization/sentence split feeds both the parser and mention extraction (run parse before coref, no re-tokenization in between)","Check that m.headIndex is within the parse tree's leaf count before constructing mentions","Use CoreNLP's own parse annotator output rather than a substitute parser with different leaf conventions","Regenerate annotations end-to-end on the current CoreNLP version"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"int leaves = m.contextParseTree.getLeaves().size();\nif (m.headIndex < 0 || m.headIndex >= leaves)\n  throw new IllegalStateException(\"headIndex \" + m.headIndex + \" out of tree leaves [0,\" + leaves + \")\");","typeGuard":null,"tryCatchPattern":"try {\n  preprocessor.preprocess(props, doc);\n} catch (RuntimeException e) {\n  if (\"Missing head tree for a mention!\".equals(e.getMessage())) {\n    logger.severe(\"Parse tree / mention index mismatch; rebuild annotations end-to-end\");\n  } else throw e;\n}","preventionTips":["Generate parse and coref from the same single pipeline pass — never mix annotations from different tokenizations","Keep the CoreNLP version uniform; regenerate all annotations after upgrades","If using an external parser, verify leaf counts match token counts per sentence"],"tags":["coref","parse-tree","index-out-of-bounds","data-consistency"],"backgroundTag":"index-out-of-bounds","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"}