{"record":{"id":"d00427c4d74094fb","repo":"stanfordnlp/CoreNLP","slug":"node-left-parent-is-not-same-as-node","errorCode":null,"errorMessage":"node left parent is not same as node!!!","messagePattern":"node left parent is not same as node!!!","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/IntervalTree.java","lineNumber":385,"sourceCode":"      int rightSize = (node.right != null)? node.right.size:0;\n      E leftMax = (node.left != null)? node.left.maxEnd:null;\n      E rightMax = (node.right != null)? node.right.maxEnd:null;\n      E maxEnd = node.value.getInterval().getEnd();\n      if (leftMax != null && leftMax.compareTo(maxEnd) > 0) {\n        maxEnd = leftMax;\n      }\n      if (rightMax != null && rightMax.compareTo(maxEnd) > 0) {\n        maxEnd = rightMax;\n      }\n      if (!maxEnd.equals(node.maxEnd)) {\n        throw new IllegalStateException(\"max end is not as expected!!!\");\n      }\n      if (node.size != leftSize + rightSize + 1) {\n        throw new IllegalStateException(\"node size is not one plus the sum of left and right!!!\");\n      }\n      if (node.left != null) {\n        if (node.left.parent != node) {\n          throw new IllegalStateException(\"node left parent is not same as node!!!\");\n        }\n      }\n      if (node.right != null) {\n        if (node.right.parent != node) {\n          throw new IllegalStateException(\"node right parent is not same as node!!!\");\n        }\n      }\n      if (node.parent != null) {\n        // Go up parent and make sure we are on correct side\n        TreeNode<E,T> n = node;\n        while (n != null && n.parent != null) {\n          // Check we are either right or left\n          if (n == n.parent.left) {\n            // Check that node is less than the parent\n            if (node.value != null) {\n              if (node.value.getInterval().compareTo(n.parent.value.getInterval()) > 0) {\n                throw new IllegalStateException(\"node is not on the correct side!!!\");\n              }","sourceCodeStart":367,"sourceCodeEnd":403,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/IntervalTree.java#L367-L403","documentation":"check() verifies parent/child linkage consistency: a node's left child must have its parent pointer set back to that node. This IllegalStateException fires when node.left != null but node.left.parent != node, i.e. the doubly-linked structure is inconsistent. It indicates that insert/remove/rotation left a child whose parent pointer points elsewhere (or null), corrupting the tree.","triggerScenarios":"check() (or balance()/rotateUp()) visits a node whose left child's parent field does not reference it — caused by a rotation or splice-out that updated child pointers without fixing the child's parent pointer.","commonSituations":"Seen while debugging tree surgery in CoreNLP (remove followed by check); after concurrent mutation of a shared IntervalTree; after external/deserialized manipulation of TreeNode fields.","solutions":["Rebuild the tree from scratch and re-insert intervals — inconsistent pointers are not locally repairable safely.","Use only the public insert/remove/overlap methods; never reassign node.left/right/parent in application code.","Serialize access to the tree (it is not thread-safe) to prevent interleaved rotations from tearing links.","If a minimal insert/remove sequence reproduces it, report to Stanford CoreNLP as a bug."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"try {\n  tree.check(tree.root);\n} catch (IllegalStateException e) {\n  // parent/child link broken -> rebuild\n}","typeGuard":null,"tryCatchPattern":"try {\n  intervalTree.insert(iv, v);\n} catch (IllegalStateException e) {\n  intervalTree = rebuildTree(allIntervals);\n}","preventionTips":["Never assign node.left/right/parent in application code.","Single-thread the tree or wrap mutations in a lock.","Keep a canonical interval collection for rebuilding.","Add check() assertions to integration tests covering remove-then-insert flows."],"tags":["interval-tree","invariant","parent-pointer","corenlp"],"backgroundTag":"internal-invariant-violation","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"}