{"record":{"id":"9cf62b930bd81c94","repo":"stanfordnlp/CoreNLP","slug":"node-is-same-as-parent","errorCode":null,"errorMessage":"node is same as parent!!!","messagePattern":"node is same as parent!!!","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/IntervalTree.java","lineNumber":339,"sourceCode":"    adjustUpwards(node, null);\n  }\n\n  // Adjust upwards starting at this node until stopAt\n  private void adjustUpwards(TreeNode<E,T> node, TreeNode<E,T> stopAt) {\n    TreeNode<E,T> n = node;\n    while (n != null && n != stopAt) {\n      int leftSize = (n.left != null)? n.left.size:0;\n      int rightSize = (n.right != null)? n.right.size:0;\n      n.maxEnd = n.value.getInterval().getEnd();\n      if (n.left != null) {\n        n.maxEnd = Interval.max(n.maxEnd, n.left.maxEnd);\n      }\n      if (n.right != null) {\n        n.maxEnd = Interval.max(n.maxEnd, n.right.maxEnd);\n      }\n      n.size = leftSize + 1 + rightSize;\n      if (n == n.parent) {\n         throw new IllegalStateException(\"node is same as parent!!!\");\n      }\n      n = n.parent;\n    }\n  }\n\n  private void adjust(TreeNode<E,T> node) {\n    adjustUpwards(node, node.parent);\n  }\n\n  public void check() {\n    check(root);\n  }\n\n  public void check(TreeNode<E,T> treeNode) {\n    Stack<TreeNode<E,T>> todo = new Stack<>();\n    todo.add(treeNode);\n    while (!todo.isEmpty()) {\n      TreeNode<E,T> node = todo.pop();","sourceCodeStart":321,"sourceCodeEnd":357,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/IntervalTree.java#L321-L357","documentation":"IntervalTree.adjustUpwards walks up the tree updating maxEnd and size aggregates. If it reaches a node whose parent pointer points at itself, the tree's structure invariant is broken, and it throws IllegalStateException 'node is same as parent!!!' to prevent an infinite loop.","triggerScenarios":"An internal invariant violation while rebalancing after remove/adjust operations — a node's parent reference equals itself, typically caused by a bug in tree surgery or by concurrent modification of the tree.","commonSituations":"Corrupted IntervalTree state after a partially failed remove; custom subclasses manipulating TreeNode links directly; unsynchronized concurrent inserts/removes.","solutions":["Report/fix the tree manipulation code; do not share the IntervalTree across threads without synchronization","Rebuild the IntervalTree from the data set instead of relying on the corrupted instance","Avoid directly mutating TreeNode parent/child links; use only public add/remove APIs"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { tree.remove(x); } catch (IllegalStateException e) { tree = new IntervalTree<>(recoveredItems); }","preventionTips":["Never mutate IntervalTree from multiple threads without external synchronization","Do not manipulate internal TreeNode links directly","Rebuild the tree if any IllegalStateException is observed; the structure is corrupt"],"tags":["interval-tree","invariant","internal-error","concurrency"],"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"}