stanfordnlp/CoreNLP · error · IllegalStateException
node size is not one plus the sum of left and right!!!
Error message
node size is not one plus the sum of left and right!!!
What it means
TreeNode caches subtree size to support balancing and ranking. check() asserts node.size == leftSize + rightSize + 1 and throws this IllegalStateException when the cached count diverges from the actual subtree. This means size counters were not maintained through some insert/remove/rotation path — internal corruption of the tree.
Solutions
- Rebuild the IntervalTree (fresh instance, re-insert all intervals) to reset all size fields.
- Only mutate through insert()/remove(); never adjust node.size or child pointers manually.
- Restrict the tree to one thread or add external synchronization — no internal locking exists.
- Capture the minimal public-API sequence that corrupts the size and file a CoreNLP bug.
Defensive patterns
Strategy: validation
Validate before calling
// Cheap post-mutation invariant check
try { tree.check(tree.root); } catch (IllegalStateException e) { corrupt = true; } Try / catch
try {
tree.remove(iv, val);
tree.check(tree.root); // dev/test builds only
} catch (IllegalStateException e) {
tree = rebuildTree(intervals);
} Prevention
- Only mutate through insert()/remove(); size fields are maintained internally.
- Avoid unsynchronized concurrent updates which can desynchronize size counters.
- Rebuild the tree after very large numbers of removals if stability is uncertain.
- Enable check() in test suites over randomized insert/remove sequences.
When it happens
Trigger: check() (directly or via balance()/rotateUp()) computes leftSize/rightSize from children and finds node.size differs from their sum plus one — typically after a rotation that forgot to recompute sizes or a remove() that decremented the wrong path.
Common situations: Hit while debugging insert/remove-heavy usage of CoreNLP's IntervalTree; after concurrent unsynchronized mutation; after code that bypassed the public API and edited node fields directly.
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 on the correct side!!!
- node is not parent's left or right child!!!
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/6bbf6bc2e0276277.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/util/IntervalTree.java:381
if (node.right != null) throw new IllegalStateException("Empty node shouldn't have right branch");
continue;
}
int leftSize = (node.left != null)? node.left.size:0;
int rightSize = (node.right != null)? node.right.size:0;
E leftMax = (node.left != null)? node.left.maxEnd:null;
E rightMax = (node.right != null)? node.right.maxEnd:null;
E maxEnd = node.value.getInterval().getEnd();
if (leftMax != null && leftMax.compareTo(maxEnd) > 0) {
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 parentView on GitHub (pinned to 1b7edd19c4)