stanfordnlp/CoreNLP · error · IllegalStateException
node is not on the correct side!!!
Error message
node is not on the correct side!!!
What it means
check() validates the BST ordering invariant by walking a node up to the root: if the node sits in its parent's LEFT subtree, its interval must compare <= every ancestor's interval on that path. This IllegalStateException fires when a left-side node's interval compares greater than its parent's, i.e. the search-order property is violated and overlap/ranking queries would return wrong answers.
Solutions
- Verify your interval type's compareTo/getInterval ordering is a proper total order consistent across all intervals.
- Rebuild the tree (new IntervalTree, re-insert intervals) to restore correct ordering.
- Do not mutate interval endpoints after insertion; remove and re-insert instead.
- Single-thread or lock access; report a minimal reproducible insert/remove sequence to CoreNLP if public API alone fails.
Example fix
// before: inconsistent comparator breaks ordering invariants
public int compareTo(Interval other) { return (int)(this.length() - other.length()); }
// after: compare by start then end, a valid total order
public int compareTo(Interval other) {
int c = this.getStart().compareTo(other.getStart());
return c != 0 ? c : this.getEnd().compareTo(other.getEnd());
} Defensive patterns
Strategy: validation
Validate before calling
// Validate comparator consistency before inserting
boolean orderingConsistent(List<Interval<E>> ivs) {
for (int i = 0; i < ivs.size(); i++)
for (int j = i + 1; j < ivs.size(); j++) {
int a = ivs.get(i).compareTo(ivs.get(j));
int b = ivs.get(j).compareTo(ivs.get(i));
if (Integer.signum(a) != -Integer.signum(b)) return false; // antisymmetry broken
}
return true;
} Try / catch
try {
tree.insert(iv, v);
tree.check(tree.root);
} catch (IllegalStateException e) {
tree = rebuildTree(intervals);
} Prevention
- Implement compareTo for intervals as a valid total order (start then end); never compare derived values like length.
- Do not mutate interval endpoints after insertion.
- Test the comparator with a sorting routine before feeding intervals to the tree.
- Keep check() enabled in tests to catch ordering drift immediately.
When it happens
Trigger: check() (or balance()/rotateUp()) climbs from a node and finds node.value.getInterval().compareTo(parent.value.getInterval()) > 0 for a node in its parent's left subtree — after a rotation or insert placed a node on the wrong side.
Common situations: Hit when the interval comparator is inconsistent with insertion order (e.g. custom Interval types with non-transitive compareTo); after concurrent mutation; after rotation bugs during rebalancing in CoreNLP.
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
- Empty node shouldn't have left branch
- Empty node shouldn't have right branch
- max end is not as expected!!!
- node is not parent's left or right child!!!
- node left parent is not same as node!!!
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/9e27cafc36fbd142.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/util/IntervalTree.java:402
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!!!");
}
} else {
throw new IllegalStateException("node is not parent's left or right child!!!");
}
n = n.parent;
}
}
if (node.left != null) todo.add(node.left);
if (node.right != null) todo.add(node.right);
}
}
View on GitHub (pinned to 1b7edd19c4)