stanfordnlp/CoreNLP · error · IllegalArgumentException
Trees constructed without CoreLabels! Can't extract…
Error message
Trees constructed without CoreLabels! Can't extract metadata!
What it means
In the same getCanditoTreeID method, if the tree's labels are not CoreLabels, the code cannot read FTB metadata at all and throws IllegalArgumentException('Trees constructed without CoreLabels! Can't extract metadata!'). This guards the cast ((CoreLabel) t.label()) used to fetch docID and sentence ID.
Solutions
- Ensure trees are read/constructed with CoreLabel factory (e.g. set the appropriate TreeReaderFactory / Label factory)
- Check the label type of the first leaf before calling canditoTreeID and reject non-CoreLabel trees
- Re-parse the source corpus with the FTB pipeline's reader rather than a generic parser
- Convert the tree's labels to CoreLabel, copying docID/sentence annotations, before extraction
Example fix
// before
String id = dataset.canditoTreeID(tree); // tree uses StringLabel
// after
if (!(tree.firstChild().label() instanceof CoreLabel)) {
throw new IllegalStateException("FTB trees must use CoreLabel");
}
String id = dataset.canditoTreeID(tree); Defensive patterns
Strategy: type-guard
Validate before calling
if (!(tree.firstChild().label() instanceof CoreLabel)) throw new IllegalStateException("FTB trees must use CoreLabel"); Type guard
boolean usesCoreLabels(Tree t){ return t.firstChild().label() instanceof CoreLabel; } Try / catch
try { String id = ds.canditoTreeID(tree); } catch (IllegalArgumentException e) { /* re-read tree with CoreLabel factory */ } Prevention
- Configure TreeReaderFactory/Label factory to produce CoreLabel-in-LabeledScoredTreeNode
- Never mix label types across corpora in the FTB pipeline
When it happens
Trigger: Calling canditoTreeID on trees whose nodes carry plain Labeled / StringLabel / CategoryWordTag labels instead of CoreLabel — e.g. trees built manually or by a reader that does not use CoreLabels.
Common situations: Mixing tree sources in the FTB pipeline; converting trees through transformations that replace CoreLabel instances with simpler label types.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- fileName , ftbID
- French does not support feature type:
- Unknown minimizer
- Unknown clique: " + clique
- Bad number put into wordToNumber. Word is: \"" + input +…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/cff2ef9063bc8d2a.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/international/french/pipeline/FTBDataset.java:77
treeFileExtension = "xml";
}
/**
* Return the ID of this tree according to the Candito split files.
*/
private String getCanditoTreeID(Tree t) {
String canditoName = null;
if (t.label() instanceof CoreLabel) {
String fileName = ((CoreLabel) t.label()).docID();
fileName = fileName.substring(0, fileName.lastIndexOf('.'));
String ftbID = ((CoreLabel) t.label()).get(CoreAnnotations.SentenceIDAnnotation.class);
if (fileName != null && ftbID != null) {
canditoName = fileName + "-" + ftbID;
} else {
throw new NullPointerException("fileName " + fileName + ", ftbID " + ftbID);
}
} else {
throw new IllegalArgumentException("Trees constructed without CoreLabels! Can't extract metadata!");
}
return canditoName;
}
@Override
public void build() {
for(File path : pathsToData) {
treebank.loadPath(path,treeFileExtension,false);
}
PrintWriter outfile = null;
PrintWriter flatFile = null;
try {
outfile = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFileName),"UTF-8")));
flatFile = (makeFlatFile) ? new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(flatFileName),"UTF-8"))) : null;
outputFileList.add(outFileName);
View on GitHub (pinned to 1b7edd19c4)