stanfordnlp/CoreNLP · error · RuntimeException
Processed trees, but there are more trees and text is empty
Error message
Processed trees, but there are more trees and text is empty
What it means
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.
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.
Example fix
// before: textIterator.next() blindly inside loop
// after: guard with hasNext and fail with alignment info
if (!textIterator.hasNext()) {
throw new IOException("Text file exhausted at tree " + graphIdx + ": CoNLL-U file and text file are misaligned");
}
String text = textIterator.next().trim(); Defensive patterns
Strategy: validation
Validate before calling
// before conversion
long textBlocks = countNonEmptyBlocks(textFile);
long trees = countConlluSentences(treeFile);
if (textBlocks < trees) throw new IllegalStateException("Text file has fewer blocks (" + textBlocks + ") than trees (" + trees + ")"); Try / catch
try { converter.main(args); } catch (RuntimeException e) { if (e.getMessage().contains("text is empty")) { /* alignment failure: verify file pairing */ } else { throw e; } } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.
Related errors
- DocumentIterator exhausted.
- CoNLL-U file and tree file are not aligned.
- ArrayCoreMap keySet iterator exhausted
- DocumentIterator exhausted.
- Graph edge iterator exhausted.
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/af46d992b4cb4b15.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/trees/ud/UniversalDependenciesConverter.java:357
if (featureAnnotator != null) {
featureAnnotator.addFeatures(sg, null, false, false);
}
}
SemanticGraph enhanced = null;
if (outputRepresentation.equalsIgnoreCase("enhanced")) {
enhanced = convertBasicToEnhanced(sg);
} else if (outputRepresentation.equalsIgnoreCase("enhanced++")) {
enhanced = convertBasicToEnhancedPlusPlus(sg);
}
if (textIterator != null) {
String text = "";
while (text.equals("")) {
try {
text = textIterator.next().trim();
} catch (NoSuchElementException e) {
throw new RuntimeException("Processed " + graphIdx + " trees, but there are more trees and text is empty", e);
}
}
addSpaceAfter(sg, text, graphIdx);
}
System.out.println("# sent_id = " + graphIdx);
System.out.print(writer.printSemanticGraph(sg, enhanced));
++graphIdx;
}
}
}
View on GitHub (pinned to 1b7edd19c4)