stanfordnlp/CoreNLP · error · IllegalStateException
Treebank: Bad tree in treebank!:
Error message
Treebank: Bad tree in treebank!:
What it means
During textualSummary statistics collection, Treebank validates tree structure: a subtree must be either a preterminal (single child) or a normal internal node; anything else (e.g. a non-preterminal leaf or a malformed structure) is reported as a bad tree via IllegalStateException.
Solutions
- Locate the offending tree (it is printed in the message) and fix or remove it from the corpus.
- Pre-validate the treebank by reading and traversing all trees before summary/training.
- Re-export the data from the original source in correct PTB bracketed format.
Example fix
// before
treebank.textualSummary(); // throws on bad tree
// after
for (Tree t : treebank) { validateTree(t); } // fix data first
treebank.textualSummary(); Defensive patterns
Strategy: validation
Validate before calling
for (Tree t : treebank) { for (Tree sub : t) { if (sub.isLeaf() && !sub.parent(t).isPreTerminal()) { log.warn("bad tree: " + sub); } } } Try / catch
try { summary = treebank.textualSummary(); } catch (IllegalStateException e) { /* quarantine the reported tree and retry */ } Prevention
- Validate corpus files conform to PTB bracketed format before loading.
- Regenerate trees from trusted parsers/tools, not hand-edited files.
- Check one offending tree at a time using the message's subtree dump.
When it happens
Trigger: Calling treebank.textualSummary() (as done after training/eval setup) when the loaded treebank contains malformed trees — typically trees where a nonterminal node has zero children or leaves appear at non-preterminal positions.
Common situations: Corrupted or non-penn-treebank-conformant corpus files; trees produced by buggy external tools; empty/whitespace-damaged files read into the Treebank.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Found a tree which was not properly binarized. So-called…
- : Bare tagged word
- : missing tag for
- after W derivative, index() != x.length()
- An error occurred while testing the tagger.
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/1b324c40ee1bc91a.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/trees/Treebank.java:410
if (tlp != null && tlp.isPunctuationTag(subtree.value())) {
puncts.incrementCount(subtree.firstChild().value());
}
} else if (subtree.isPhrasal()) {
boolean hasLeafChild = false;
for (Tree kt : subtree.children()) {
if (kt.isLeaf()) {
hasLeafChild = true;
}
}
if (hasLeafChild) {
numPreTerminalWithMultipleChildren++;
if (preTerminalMultipleChildrenEg == null) {
preTerminalMultipleChildrenEg = subtree;
}
}
cats.incrementCount(subtree.value());
} else {
throw new IllegalStateException("Treebank: Bad tree in treebank!: " + subtree);
}
}
}
StringWriter sw = new StringWriter(2000);
PrintWriter pw = new PrintWriter(sw);
NumberFormat nf = NumberFormat.getNumberInstance();
nf.setMaximumFractionDigits(0);
pw.println("Treebank has " + numTrees + " trees (" + numTreesLE40 + " of length <= 40) and " + numWords + " words (tokens)");
if (numTrees > 0) {
if (numTags != numWords) {
pw.println(" Warning! numTags differs and is " + numTags);
}
if (roots.size() == 1) {
String root = (String) roots.keySet().toArray()[0];
pw.println(" The root category is: " + root);
} else {
pw.println(" Warning! " + roots.size() + " different roots in treebank: " + Counters.toString(roots, nf));
pw.println(" Examples:");View on GitHub (pinned to 1b7edd19c4)