{"record":{"id":"cff2ef9063bc8d2a","repo":"stanfordnlp/CoreNLP","slug":"trees-constructed-without-corelabels-can-t-extrac","errorCode":null,"errorMessage":"Trees constructed without CoreLabels! Can't extract metadata!","messagePattern":"Trees constructed without CoreLabels! Can't extract metadata!","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/international/french/pipeline/FTBDataset.java","lineNumber":77,"sourceCode":"    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;\n\n      outputFileList.add(outFileName);\n","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/international/french/pipeline/FTBDataset.java#L59-L95","documentation":"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.","triggerScenarios":"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.","commonSituations":"Mixing tree sources in the FTB pipeline; converting trees through transformations that replace CoreLabel instances with simpler label types.","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"],"exampleFix":"// before\nString id = dataset.canditoTreeID(tree); // tree uses StringLabel\n// after\nif (!(tree.firstChild().label() instanceof CoreLabel)) {\n  throw new IllegalStateException(\"FTB trees must use CoreLabel\");\n}\nString id = dataset.canditoTreeID(tree);","handlingStrategy":"type-guard","validationCode":"if (!(tree.firstChild().label() instanceof CoreLabel)) throw new IllegalStateException(\"FTB trees must use CoreLabel\");","typeGuard":"boolean usesCoreLabels(Tree t){ return t.firstChild().label() instanceof CoreLabel; }","tryCatchPattern":"try { String id = ds.canditoTreeID(tree); } catch (IllegalArgumentException e) { /* re-read tree with CoreLabel factory */ }","preventionTips":["Configure TreeReaderFactory/Label factory to produce CoreLabel-in-LabeledScoredTreeNode","Never mix label types across corpora in the FTB pipeline"],"tags":["java","nlp","french","label-type","metadata"],"backgroundTag":"type-mismatch","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"}