stanfordnlp/CoreNLP · error · IllegalStateException

node right parent is not same as node!!!

Error message

node right parent is not same as node!!!

What it means

check() verifies parent/child linkage consistency: a node's right child must have its parent pointer set back to that node. This IllegalStateException fires when node.right != null but node.right.parent != node, meaning the tree's bidirectional links are out of sync. Like its left-child counterpart, it signals internal structural corruption from a failed update or rotation.

Solutions

  1. Rebuild the IntervalTree and re-insert all intervals to restore consistent links.
  2. Restrict all mutations to the public API; do not touch TreeNode internals.
  3. Add external locking or single-thread the tree's use to avoid interleaved structural updates.
  4. Minimize the reproducing operation sequence and report upstream if public API alone triggers it.
Defensive patterns

Strategy: try-catch

Validate before calling

try {
  tree.check(tree.root);
} catch (IllegalStateException e) {
  // right-child parent link broken -> rebuild
}

Try / catch

try {
  tree.check(tree.root);
} catch (IllegalStateException e) {
  if (e.getMessage().contains("right parent")) { tree = rebuildTree(intervals); }
}

Prevention

When it happens

Trigger: check() (or balance()/rotateUp() that call it) visits a node whose right child's parent field references a different node (or null) — typically after rotateUp or remove updated one side of the link but not the other.

Common situations: Encountered debugging CoreNLP interval-tree removals or rebalances; after unsynchronized concurrent access; after subclass or reflection code altered node fields.

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/3e48fe1055318f5e. Report an issue: GitHub.

Appendix: source

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

        maxEnd = leftMax;
      }
      if (rightMax != null && rightMax.compareTo(maxEnd) > 0) {
        maxEnd = rightMax;
      }
      if (!maxEnd.equals(node.maxEnd)) {
        throw new IllegalStateException("max end is not as expected!!!");
      }
      if (node.size != leftSize + rightSize + 1) {
        throw new IllegalStateException("node size is not one plus the sum of left and right!!!");
      }
      if (node.left != null) {
        if (node.left.parent != node) {
          throw new IllegalStateException("node left parent is not same as node!!!");
        }
      }
      if (node.right != null) {
        if (node.right.parent != node) {
          throw new IllegalStateException("node right parent is not same as node!!!");
        }
      }
      if (node.parent != null) {
        // Go up parent and make sure we are on correct side
        TreeNode<E,T> n = node;
        while (n != null && n.parent != null) {
          // Check we are either right or left
          if (n == n.parent.left) {
            // Check that node is less than the parent
            if (node.value != null) {
              if (node.value.getInterval().compareTo(n.parent.value.getInterval()) > 0) {
                throw new IllegalStateException("node is not on the correct side!!!");
              }
            }
          } else if (n == n.parent.right) {
            // Check that node is greater than the parent
            if (node.value.getInterval().compareTo(n.parent.value.getInterval()) <= 0) {
              throw new IllegalStateException("node is not on the correct side!!!");

View on GitHub (pinned to 1b7edd19c4)