stanfordnlp/CoreNLP · error · IllegalStateException
Not on parent's left or right branches.
Error message
Not on parent's left or right branches.
What it means
IntervalTree.rotateUp walks up the tree splaying/rotating nodes toward the root. Each node must be linked to its parent via the parent's left or right child pointer; if a node's parent reference is set but the parent does not point back to it, the tree's link invariants are broken and the library refuses to guess a rotation direction.
Solutions
- Do not mutate IntervalTree node parent/left/right fields directly; only use the public add/remove/query API
- Rebuild the tree from its elements if corruption is suspected (new IntervalTree + re-add all values)
- Check any overridden or wrapped IntervalTree operations for missed adjust()/parent reassignment steps
- Report the bug with a minimal reproduction if it occurs through public API only
Example fix
// before: manual mutation node.parent.left = otherNode; // breaks back-pointer, rotateUp throws // after intervalTree.remove(node.value); intervalTree.add(otherValue); // let the tree maintain invariants
Defensive patterns
Strategy: validation
Validate before calling
if (n.parent == null || (n.parent.left != n && n.parent.right != n)) {
throw new IllegalStateException("node not linked to parent; tree corrupted");
}
tree.rotateUp(n); // safe Type guard
boolean isLinkedToParent(Node n) {
return n.parent != null && (n.parent.left == n || n.parent.right == n);
} Try / catch
try {
tree.rotateUp(node);
} catch (IllegalStateException e) {
// tree invariants broken: rebuild
tree = rebuildFromElements(elements);
} Prevention
- Never mutate IntervalTree node pointers directly
- Use only public add/remove/contains API
- Rebuild the tree instead of patching corrupted links
- Add debug-mode check() calls after custom operations
When it happens
Trigger: Calling rotateUp (directly or via balance) on a node whose parent pointer is non-null but whose parent's left/right references were corrupted by manual mutation of IntervalTree nodes, incorrect custom rebalancing, or a stale parent reference after an out-of-band remove.
Common situations: Custom code poking at the internal node fields, subclassing IntervalTree and overriding adjust/remove, or a bug in another operation that left parent/child pointers asymmetric.
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
- Old root not a child of it's parent
- allSentences != allWords
- Empty node shouldn't have left branch
- Empty node shouldn't have right branch
- Error -- attempt to operate with key of wrong length…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/c9ad0837c7def604.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/util/IntervalTree.java:472
if (median.right != null) todo.push(median.right);
}
if (newRoot == null) return node;
else return newRoot;
}
// Moves this node up the tree until it replaces the target node
public void rotateUp(TreeNode<E,T> node, TreeNode<E,T> target) {
TreeNode<E,T> n = node;
boolean done = false;
while (n != null && n.parent != null && !done) {
// Check if we are the left or right child
done = (n.parent == target);
if (n == n.parent.left) {
n = rightRotate(n.parent);
} else if (n == n.parent.right) {
n = leftRotate(n.parent);
} else {
throw new IllegalStateException("Not on parent's left or right branches.");
}
if (debug) check(n);
}
}
// Moves this node to the right and the left child up and returns the new root
public TreeNode<E,T> rightRotate(TreeNode<E,T> oldRoot) {
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;View on GitHub (pinned to 1b7edd19c4)