stanfordnlp/CoreNLP · error · RuntimeException
Tree is not a descendant of root.
Error message
Tree is not a descendant of root.
What it means
Trees.leftEdge(t, root) computes t's token position at the left edge by walking from root; the helper returns false when t is not reachable within root's subtree, so the public method throws RuntimeException.
Solutions
- Ensure root is the actual containing tree of t (use the same Tree object hierarchy).
- Pass the sentence's full Tree as root, not a sibling or unrelated subtree.
- Catch RuntimeException and return -1 / handle the disjoint-tree case explicitly.
Example fix
// before
int edge = Trees.leftEdge(subtree, otherTreeRoot);
// after
if (Trees.isIn(subtree, root)) { int edge = Trees.leftEdge(subtree, root); } Defensive patterns
Strategy: try-catch
Validate before calling
// containment check
boolean contains(Tree root, Tree t) { for (Tree sub : root) if (sub == t) return true; return false; } Try / catch
try { edge = Trees.leftEdge(t, root); } catch (RuntimeException e) { edge = -1; /* t not under root */ } Prevention
- Always pass the tree that actually contains the node as root.
- Keep subtree references from the same parse as the root.
- Re-acquire both t and root from the same Tree object after re-parsing.
When it happens
Trigger: Calling Trees.leftEdge(t, root) where t belongs to a different tree than root, or t is not actually a descendant of root (e.g. a subtree copied out of the original tree, or two disjoint trees compared).
Common situations: Comparing nodes from parse trees of different sentences; using a stale subtree reference after re-parsing; mixing trees from gold and guess Treebanks in evaluation code.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- t insert tree after the
- ancestor: height cannot be negative
- Attempt to open file with null name
- Bad arguments: " + x + " and " + lambda
- Bad tree state:
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/6894c0ddc381b77e.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/trees/Trees.java:50
}
int maxHeight = 0;
for (Tree child : t.children()) {
maxHeight = Math.max(maxHeight, height(child));
}
return maxHeight + 1;
}
/**
* Returns the positional index of the left edge of a tree <i>t</i>
* within a given root, as defined by the size of the yield of all
* material preceding <i>t</i>.
*/
public static int leftEdge(Tree t, Tree root) {
MutableInteger i = new MutableInteger(0);
if (leftEdge(t, root, i)) {
return i.intValue();
} else {
throw new RuntimeException("Tree is not a descendant of root.");
// return -1;
}
}
/**
* Returns the positional index of the left edge of a tree <i>t</i>
* within a given root, as defined by the size of the yield of all
* material preceding <i>t</i>.
* This method returns -1 if no path is found, rather than exceptioning.
*
* @see Trees#leftEdge(Tree, Tree)
*/
public static int leftEdgeUnsafe(Tree t, Tree root) {
MutableInteger i = new MutableInteger(0);
if (leftEdge(t, root, i)) {
return i.intValue();
} else {
return -1;View on GitHub (pinned to 1b7edd19c4)