stanfordnlp/CoreNLP · error · IllegalStateException

node is same as parent!!!

Error message

node is same as parent!!!

What it means

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.

Solutions

  1. Report/fix the tree manipulation code; do not share the IntervalTree across threads without synchronization
  2. Rebuild the IntervalTree from the data set instead of relying on the corrupted instance
  3. Avoid directly mutating TreeNode parent/child links; use only public add/remove APIs
Defensive patterns

Strategy: try-catch

Try / catch

try { tree.remove(x); } catch (IllegalStateException e) { tree = new IntervalTree<>(recoveredItems); }

Prevention

When it happens

Trigger: 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.

Common situations: Corrupted IntervalTree state after a partially failed remove; custom subclasses manipulating TreeNode links directly; unsynchronized concurrent inserts/removes.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/9cf62b930bd81c94. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/util/IntervalTree.java:339

    adjustUpwards(node, null);
  }

  // Adjust upwards starting at this node until stopAt
  private void adjustUpwards(TreeNode<E,T> node, TreeNode<E,T> stopAt) {
    TreeNode<E,T> n = node;
    while (n != null && n != stopAt) {
      int leftSize = (n.left != null)? n.left.size:0;
      int rightSize = (n.right != null)? n.right.size:0;
      n.maxEnd = n.value.getInterval().getEnd();
      if (n.left != null) {
        n.maxEnd = Interval.max(n.maxEnd, n.left.maxEnd);
      }
      if (n.right != null) {
        n.maxEnd = Interval.max(n.maxEnd, n.right.maxEnd);
      }
      n.size = leftSize + 1 + rightSize;
      if (n == n.parent) {
         throw new IllegalStateException("node is same as parent!!!");
      }
      n = n.parent;
    }
  }

  private void adjust(TreeNode<E,T> node) {
    adjustUpwards(node, node.parent);
  }

  public void check() {
    check(root);
  }

  public void check(TreeNode<E,T> treeNode) {
    Stack<TreeNode<E,T>> todo = new Stack<>();
    todo.add(treeNode);
    while (!todo.isEmpty()) {
      TreeNode<E,T> node = todo.pop();

View on GitHub (pinned to 1b7edd19c4)