{"record":{"id":"af46d992b4cb4b15","repo":"stanfordnlp/CoreNLP","slug":"processed-trees-but-there-are-more-trees-and-tex","errorCode":null,"errorMessage":"Processed  trees, but there are more trees and text is empty","messagePattern":"Processed  trees, but there are more trees and text is empty","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/ud/UniversalDependenciesConverter.java","lineNumber":357,"sourceCode":"\n        if (featureAnnotator != null) {\n          featureAnnotator.addFeatures(sg, null, false, false);\n        }\n      }\n\n      SemanticGraph enhanced = null;\n      if (outputRepresentation.equalsIgnoreCase(\"enhanced\")) {\n        enhanced = convertBasicToEnhanced(sg);\n      } else if (outputRepresentation.equalsIgnoreCase(\"enhanced++\")) {\n        enhanced = convertBasicToEnhancedPlusPlus(sg);\n      }\n      if (textIterator != null) {\n        String text = \"\";\n        while (text.equals(\"\")) {\n          try {\n            text = textIterator.next().trim();\n          } catch (NoSuchElementException e) {\n            throw new RuntimeException(\"Processed \" + graphIdx + \" trees, but there are more trees and text is empty\", e);\n          }\n        }\n        addSpaceAfter(sg, text, graphIdx);\n      }\n      System.out.println(\"# sent_id = \" + graphIdx);\n      System.out.print(writer.printSemanticGraph(sg, enhanced));\n      ++graphIdx;\n    }\n\n  }\n\n}\n","sourceCodeStart":339,"sourceCodeEnd":370,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/ud/UniversalDependenciesConverter.java#L339-L370","documentation":"UniversalDependenciesConverter wraps a NoSuchElementException thrown while draining a text iterator that has run out of elements. The converter aligns a CoNLL-U tree stream with an external raw-text stream; if the text iterator is exhausted (next() throws) it means the two inputs are out of sync or the text file is shorter than the tree file. It reports how many trees (graphIdx) were successfully processed before the mismatch.","triggerScenarios":"Calling main() with a text iterator (e.g. backed by a separate text file) whose hasNext() reports true or whose remaining empty strings still need skipping, but whose next() throws NoSuchElementException — i.e. the iterator is empty while more trees remain to be converted at index graphIdx.","commonSituations":"Passing a CoNLL-U file with more sentences than the parallel text file; text file has trailing blank lines consumed differently; off-by-one in sentence splitting (extra blank line at end of tree file creating one more 'tree'); misaligned or wrong pair of files supplied.","solutions":["Check the text file has at least as many non-empty text blocks as the CoNLL-U file has sentences (compare sentence counts).","Fix sentence/paragraph splitting of the text file so blank-line separation matches the tree file's blank-line-separated CoNLL-U blocks.","Ensure the same file order/pairing is passed to main(); verify no stale/older text file is used.","Catch NoSuchElementException at the call site and log graphIdx to locate the first misaligned sentence."],"exampleFix":"// before: textIterator.next() blindly inside loop\n// after: guard with hasNext and fail with alignment info\nif (!textIterator.hasNext()) {\n  throw new IOException(\"Text file exhausted at tree \" + graphIdx + \": CoNLL-U file and text file are misaligned\");\n}\nString text = textIterator.next().trim();","handlingStrategy":"validation","validationCode":"// before conversion\nlong textBlocks = countNonEmptyBlocks(textFile);\nlong trees = countConlluSentences(treeFile);\nif (textBlocks < trees) throw new IllegalStateException(\"Text file has fewer blocks (\" + textBlocks + \") than trees (\" + trees + \")\");","typeGuard":null,"tryCatchPattern":"try { converter.main(args); } catch (RuntimeException e) { if (e.getMessage().contains(\"text is empty\")) { /* alignment failure: verify file pairing */ } else { throw e; } }","preventionTips":["Always generate the text file and CoNLL-U file from the same corpus snapshot.","Compare sentence counts of both files before running conversion.","Keep blank-line separation semantics identical in both files."],"tags":["iterator","alignment","nosuch-element","conllu"],"backgroundTag":"empty-result-set","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"}