stanfordnlp/CoreNLP · error · NullPointerException
fileName , ftbID
Error message
fileName , ftbID
What it means
FTBDataset.getCanditoTreeID builds the Candito treebank tree ID from a tree's metadata: the source fileName (from CoreLabel docID) and ftbID (SentenceIDAnnotation). It throws NullPointerException('fileName ..., ftbID ...') when either piece of metadata is null after substring extraction, since a valid ID cannot be constructed.
Solutions
- Load FTB trees with the pipeline's readers so docID and SentenceIDAnnotation are populated
- Verify every tree leaf has a non-null docID ending in a proper file extension before conversion
- Null-check the annotations in calling code and skip/log trees missing FTB metadata
- Set the missing annotations manually if the trees come from another source
Example fix
// before
String id = dataset.canditoTreeID(tree); // NPE when metadata absent
// after
CoreLabel first = (CoreLabel) tree.firstChild().label();
if (first.docID() == null || first.get(CoreAnnotations.SentenceIDAnnotation.class) == null) {
return; // skip or log tree lacking FTB metadata
}
String id = dataset.canditoTreeID(tree); Defensive patterns
Strategy: validation
Validate before calling
CoreLabel leaf = (CoreLabel) tree.firstChild().label(); boolean ready = leaf != null && leaf.docID() != null && leaf.get(CoreAnnotations.SentenceIDAnnotation.class) != null; if (!ready) skipTree(tree); // log and continue
Type guard
boolean hasFtbMetadata(Tree t){ Label l = t.firstChild().label(); return l instanceof CoreLabel && ((CoreLabel) l).docID() != null && ((CoreLabel) l).get(CoreAnnotations.SentenceIDAnnotation.class) != null; } Try / catch
try { String id = ds.canditoTreeID(tree); } catch (NullPointerException e) { /* tree lacks FTB metadata; skip */ } Prevention
- Load FTB corpora only with the pipeline readers that populate docID and SentenceIDAnnotation
- Pre-scan trees for missing metadata before running the conversion pipeline
When it happens
Trigger: Calling canditoTreeID(tree) on a tree read from a source whose leaves lack CoreLabel docID or SentenceIDAnnotation — e.g. trees not loaded via the FTB reading pipeline, or a file name without the expected '.' extension making lastIndexOf('.')->substring produce unexpected values.
Common situations: Running the French treebank conversion pipeline on trees created programmatically or loaded from a generic reader that does not populate FTB document/sentence annotations.
Related errors
- Trees constructed without CoreLabels! Can't extract…
- 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/4653041d4b103174.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/international/french/pipeline/FTBDataset.java:74
//stats for MWE pre-processing
// The treebank may be reset if setOptions changes CC_TAGSET
treebank = new MemoryTreebank(new FrenchXMLTreeReaderFactory(CC_TAGSET), FrenchTreebankLanguagePack.FTB_ENCODING);
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;View on GitHub (pinned to 1b7edd19c4)