stanfordnlp/CoreNLP · error · java.util.NoSuchElementException
No more elements from
Error message
No more elements from ${inputDesc} What it means
CharniakScoredParsesReaderWriter's ScoredParsesIterator.next() throws NoSuchElementException when the underlying input has no more scored parses to read. This is the standard Iterator contract: next() called past the end of the parse stream. inputDesc identifies which input file/stream was exhausted.
Solutions
- Guard each call with iterator.hasNext() before calling next()
- Use a for-each loop over the iterable instead of manual next() calls
- Verify the input parse file is complete and not truncated
Example fix
// before
while (true) { ScoredObject<Tree> so = it.next(); ... }
// after
while (it.hasNext()) { ScoredObject<Tree> so = it.next(); ... } Defensive patterns
Strategy: type-guard
Validate before calling
if (it == null || !it.hasNext()) { return Collections.emptyListIterator(); } Type guard
static <T> Optional<T> nextIfPresent(Iterator<T> it) { return it != null && it.hasNext() ? Optional.of(it.next()) : Optional.empty(); } Try / catch
try { so = it.next(); } catch (NoSuchElementException e) { log.warn("parse stream exhausted early: " + inputDesc); break; } Prevention
- Always iterate with hasNext() or for-each, never bare next() calls
- Validate that parse dump files contain the expected number of entries before consuming them
- Handle truncated inputs gracefully instead of assuming fixed k-best counts
When it happens
Trigger: Calling next() on the returned iterator after hasNext() returned false, or calling next() without checking hasNext() while iterating a Charniak parse dump file that has fewer entries than expected.
Common situations: Assuming a k-best parse file always contains k parses per sentence; iterating with next() instead of a hasNext() guard; a truncated or corrupt parse dump ending earlier than the driver loop expects.
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.
- DocumentIterator exhausted.
- DocumentIterator exhausted.
- TreeIterator exhausted
- Empty PQ
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/ad3f8a0a732ec63f.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/charniak/CharniakScoredParsesReaderWriter.java:253
public List<ScoredObject<Tree>> next() {
if (!done) {
List<ScoredObject<Tree>> cur = next;
next = getNext();
processed++;
if (next == null) {
logger.info("Read " + processed + " trees, from "
+ inputDesc + " in " + timing.toSecondsString() + " secs");
done = true;
if (closeBufferNeeded) {
try { br.close();
} catch (IOException ex) {
logger.warn(ex);
}
}
}
return cur;
} else {
throw new NoSuchElementException("No more elements from " + inputDesc);
}
}
} // end static class ScoredParsesIterator
}
View on GitHub (pinned to 1b7edd19c4)