{"record":{"id":"e15a8987dabd87b1","repo":"stanfordnlp/CoreNLP","slug":"node-is-not-parent-s-left-or-right-child","errorCode":null,"errorMessage":"node is not parent's left or right child!!!","messagePattern":"node is not parent's left or right child!!!","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/util/IntervalTree.java","lineNumber":411,"sourceCode":"      if (node.parent != null) {\n        // Go up parent and make sure we are on correct side\n        TreeNode<E,T> n = node;\n        while (n != null && n.parent != null) {\n          // Check we are either right or left\n          if (n == n.parent.left) {\n            // Check that node is less than the parent\n            if (node.value != null) {\n              if (node.value.getInterval().compareTo(n.parent.value.getInterval()) > 0) {\n                throw new IllegalStateException(\"node is not on the correct side!!!\");\n              }\n            }\n          } else if (n == n.parent.right) {\n            // Check that node is greater than the parent\n            if (node.value.getInterval().compareTo(n.parent.value.getInterval()) <= 0) {\n              throw new IllegalStateException(\"node is not on the correct side!!!\");\n            }\n          } else {\n            throw new IllegalStateException(\"node is not parent's left or right child!!!\");\n          }\n          n = n.parent;\n        }\n      }\n      if (node.left != null) todo.add(node.left);\n      if (node.right != null) todo.add(node.right);\n    }\n  }\n\n\n  public boolean isAlphaBalanced(TreeNode<E,T> node, double alpha) {\n    int leftSize = (node.left != null)? node.left.size:0;\n    int rightSize = (node.right != null)? node.right.size:0;\n    int threshold = (int) (alpha*node.size) + 1;\n    return (leftSize <= threshold) && (rightSize <= threshold);\n  }\n\n  public void balance() {","sourceCodeStart":393,"sourceCodeEnd":429,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/util/IntervalTree.java#L393-L429","documentation":"While validating ordering, check() walks from a node up through n.parent and asserts n is either n.parent.left or n.parent.right. If it is neither, this IllegalStateException fires: the node is unreachable as a proper child of its claimed parent, i.e. the tree's parent/child links are torn. This is a catch-all corruption detector in the validator, thrown as an internal invariant failure.","triggerScenarios":"check() (or balance()/rotateUp()) climbs an ancestry chain and reaches a node whose parent pointer exists but whose parent's left/right fields don't include it — after a rotation spliced pointers incorrectly or a remove left a phantom parent link.","commonSituations":"Hit during CoreNLP interval-tree debugging after failed rotations; after concurrent unsynchronized insert/remove; after external code or custom subclasses re-linking nodes.","solutions":["Rebuild the IntervalTree from scratch and re-insert all intervals.","Never modify TreeNode parent/left/right pointers outside the library's own algorithms.","Serialize all access to the tree (no internal thread safety) to avoid interleaved structural updates.","Capture a minimal insert/remove/rotate sequence and report it to Stanford CoreNLP if reproducible via public API."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"try {\n  tree.check(tree.root);\n} catch (IllegalStateException e) {\n  // ancestry chain broken -> rebuild from source intervals\n}","typeGuard":null,"tryCatchPattern":"try {\n  intervalTree.remove(iv, v);\n  intervalTree.check(intervalTree.root);\n} catch (IllegalStateException e) {\n  intervalTree = rebuildTree(intervals);\n}","preventionTips":["Never store and re-use TreeNode references across tree mutations.","Confine the tree to one thread or synchronize all access.","Rebuild from the canonical interval list whenever any invariant check fails.","Include randomized insert/remove + check() tests in CI to surface corruption early."],"tags":["interval-tree","invariant","parent-pointer","corenlp"],"backgroundTag":"internal-invariant-violation","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}