{"record":{"id":"4653041d4b103174","repo":"stanfordnlp/CoreNLP","slug":"filename-ftbid","errorCode":null,"errorMessage":"fileName , ftbID ","messagePattern":"fileName , ftbID ","errorType":"exception","errorClass":"NullPointerException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/international/french/pipeline/FTBDataset.java","lineNumber":74,"sourceCode":"    //stats for MWE pre-processing\n    // The treebank may be reset if setOptions changes CC_TAGSET\n    treebank = new MemoryTreebank(new FrenchXMLTreeReaderFactory(CC_TAGSET), FrenchTreebankLanguagePack.FTB_ENCODING);\n    treeFileExtension = \"xml\";\n  }\n\n  /**\n   * Return the ID of this tree according to the Candito split files.\n   */\n  private String getCanditoTreeID(Tree t) {\n    String canditoName = null;\n    if (t.label() instanceof CoreLabel) {\n      String fileName = ((CoreLabel) t.label()).docID();\n      fileName = fileName.substring(0, fileName.lastIndexOf('.'));\n      String ftbID = ((CoreLabel) t.label()).get(CoreAnnotations.SentenceIDAnnotation.class);\n      if (fileName != null && ftbID != null) {\n        canditoName = fileName + \"-\" + ftbID;\n      } else {\n        throw new NullPointerException(\"fileName \" + fileName + \", ftbID \" + ftbID);\n      }\n    } else {\n      throw new IllegalArgumentException(\"Trees constructed without CoreLabels! Can't extract metadata!\");\n    }\n    return canditoName;\n  }\n\n  @Override\n  public void build() {\n    for(File path : pathsToData) {\n      treebank.loadPath(path,treeFileExtension,false);\n    }\n\n    PrintWriter outfile = null;\n    PrintWriter flatFile = null;\n    try {\n      outfile = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFileName),\"UTF-8\")));\n      flatFile = (makeFlatFile) ? new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(flatFileName),\"UTF-8\"))) : null;","sourceCodeStart":56,"sourceCodeEnd":92,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/international/french/pipeline/FTBDataset.java#L56-L92","documentation":"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.","triggerScenarios":"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.","commonSituations":"Running the French treebank conversion pipeline on trees created programmatically or loaded from a generic reader that does not populate FTB document/sentence annotations.","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"],"exampleFix":"// before\nString id = dataset.canditoTreeID(tree); // NPE when metadata absent\n// after\nCoreLabel first = (CoreLabel) tree.firstChild().label();\nif (first.docID() == null || first.get(CoreAnnotations.SentenceIDAnnotation.class) == null) {\n  return; // skip or log tree lacking FTB metadata\n}\nString id = dataset.canditoTreeID(tree);","handlingStrategy":"validation","validationCode":"CoreLabel leaf = (CoreLabel) tree.firstChild().label();\nboolean ready = leaf != null && leaf.docID() != null\n  && leaf.get(CoreAnnotations.SentenceIDAnnotation.class) != null;\nif (!ready) skipTree(tree); // log and continue","typeGuard":"boolean hasFtbMetadata(Tree t){ Label l = t.firstChild().label(); return l instanceof CoreLabel && ((CoreLabel) l).docID() != null && ((CoreLabel) l).get(CoreAnnotations.SentenceIDAnnotation.class) != null; }","tryCatchPattern":"try { String id = ds.canditoTreeID(tree); } catch (NullPointerException e) { /* tree lacks FTB metadata; skip */ }","preventionTips":["Load FTB corpora only with the pipeline readers that populate docID and SentenceIDAnnotation","Pre-scan trees for missing metadata before running the conversion pipeline"],"tags":["java","nlp","french","null-pointer","metadata"],"backgroundTag":"null-argument","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}