stanfordnlp/CoreNLP · error · IllegalStateException
Old root not a child of it's parent
Error message
Old root not a child of it's parent
What it means
rightRotate moves oldRoot down to the left and its left child up. After rotating, if the new root still has a parent, that parent's child pointer must reference oldRoot before the rotation so it can be swapped to newRoot; if neither parent.left nor parent.right equals oldRoot, the tree linkage is inconsistent and the library throws instead of silently corrupting the tree.
Solutions
- Avoid direct manipulation of IntervalTree internals; use add/remove API
- Verify parent/child back-pointers are symmetric before invoking rotation helpers
- Rebuild the tree from its elements to restore invariants
- File a bug with reproduction if reachable via public API
Example fix
// before someNode.parent = p; // p.left/right not updated IntervalTree.Node r = tree.rightRotate(someNode); // throws // after // reattach via the tree API so p.left/right and someNode.parent stay consistent
Defensive patterns
Strategy: validation
Validate before calling
if (newRoot.parent != null && newRoot.parent.left != oldRoot && newRoot.parent.right != oldRoot) {
throw new IllegalStateException("rotation precondition violated");
}
Node r = tree.rightRotate(oldRoot); Type guard
boolean isChildOfParent(Node oldRoot) {
return oldRoot.parent == null || oldRoot.parent.left == oldRoot || oldRoot.parent.right == oldRoot;
} Try / catch
try {
Node r = tree.rightRotate(node);
} catch (IllegalStateException e) {
// restore via rebuild; do not continue with corrupted tree
tree = rebuildFromElements(elements);
} Prevention
- Keep parent/child back-pointers symmetric when doing any tree surgery
- Prefer public API over calling rotation helpers directly
- Run IntervalTree's debug check() after structural changes
- Treat the tree as unusable after this exception
When it happens
Trigger: Calling rightRotate on a node whose parent pointer is stale or whose parent's child pointers no longer reference it — typically after manual node mutation or an out-of-band structural change.
Common situations: Hand-written tree surgery, subclass overrides, or debugging experiments that detach/reattach nodes without updating the symmetric pointer.
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
- Not on parent's left or right branches.
- allSentences != allWords
- Error -- attempt to operate with key of wrong length…
- Error: cannot insert multiple keys with the same value
- mapDependencies: HeadFinder failed!
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/66e41f44a390c5f4.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/util/IntervalTree.java:498
if (oldRoot == null || oldRoot.isEmpty() || oldRoot.left == null) return oldRoot;
TreeNode<E,T> oldLeftRight = oldRoot.left.right;
TreeNode<E,T> newRoot = oldRoot.left;
newRoot.right = oldRoot;
oldRoot.left = oldLeftRight;
// Adjust parents and such
newRoot.parent = oldRoot.parent;
newRoot.maxEnd = oldRoot.maxEnd;
newRoot.size = oldRoot.size;
if (newRoot.parent != null) {
if (newRoot.parent.left == oldRoot) {
newRoot.parent.left = newRoot;
} else if (newRoot.parent.right == oldRoot) {
newRoot.parent.right = newRoot;
} else {
throw new IllegalStateException("Old root not a child of it's parent");
}
}
oldRoot.parent = newRoot;
if (oldLeftRight != null) oldLeftRight.parent = oldRoot;
adjust(oldRoot);
return newRoot;
}
// Moves this node to the left and the right child up and returns the new root
public TreeNode<E,T> leftRotate(TreeNode<E,T> oldRoot) {
if (oldRoot == null || oldRoot.isEmpty() || oldRoot.right == null) return oldRoot;
TreeNode<E,T> oldRightLeft = oldRoot.right.left;
TreeNode<E,T> newRoot = oldRoot.right;
newRoot.left = oldRoot;
oldRoot.right = oldRightLeft;View on GitHub (pinned to 1b7edd19c4)