stanfordnlp/CoreNLP · error · IllegalArgumentException
Error -- no such thing as zeroth child!
Error message
Error -- no such thing as zeroth child!
What it means
Tregex's IthChildOf relation (>i or >-i) selects the i-th child of a node, with 1-based indexing (negative for counting from the end). i == 0 has no meaning (there is no zeroth child), so the constructor throws IllegalArgumentException.
Solutions
- Use >1 for the first child (or >-1 for the last)
- Adjust programmatic index generation to be 1-based
- Validate user-supplied child indices != 0 before compiling the pattern
Example fix
// before String pattern = "S >" + childIdx; // childIdx == 0 // after String pattern = "S >" + (childIdx + 1); // first child is >1
Defensive patterns
Strategy: validation
Validate before calling
if (i == 0) throw new IllegalArgumentException("child index must be nonzero (1-based), got 0"); Type guard
boolean validChildIndex(int i) { return i != 0; } Try / catch
try { TregexPattern.compile(pattern); } catch (IllegalArgumentException e) { /* report bad >i index */ } Prevention
- First child is >1, last is >-1; 0 is always invalid
- Sanitize user-supplied indices before building patterns
- Add compile() smoke tests for generated queries
When it happens
Trigger: A tregex pattern contains '>0' (e.g. "NP>0"), so the parser constructs IthChildOf(0) and the constructor throws.
Common situations: Zero-based habits from array indexing leak into hand-written tregex queries; generated queries with loop counters starting at 0; users misremembering whether >1 is the first child.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Error -- no such thing as zeroth leaf!
- Node cannot be both negated and optional.
- after edge derivative, index() != edgeParamCount()
- after W derivative, index() != beforeOutputWeights()
- after W derivative, index() != x.length()
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/42c408a38efc2b8f.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/trees/tregex/Relation.java:1368
public int hashCode() {
int result = super.hashCode();
result = 29 * result
+ (immediatelyHeads != null ? immediatelyHeads.hashCode() : 0);
return result;
}
}
private static class IthChildOf extends Relation {
private static final long serialVersionUID = -1463126827537879633L;
private final int childNum;
IthChildOf(int i) {
super('>' + String.valueOf(i));
if (i == 0) {
throw new IllegalArgumentException(
"Error -- no such thing as zeroth child!");
} else {
childNum = i;
}
}
@Override
Iterator<Tree> searchNodeIterator(final Tree t,
final TregexMatcher matcher) {
return new SearchNodeIterator() {
@Override
void initialize() {
if (t != matcher.getRoot()) {
next = matcher.getParent(t);
if (childNum > 0
&& (next.numChildren() < childNum || next
.getChild(childNum - 1) != t)
|| childNum < 0View on GitHub (pinned to 1b7edd19c4)