stanfordnlp/CoreNLP · warning · NoSuchElementException
ArrayCoreMap keySet iterator exhausted
Error message
ArrayCoreMap keySet iterator exhausted
What it means
ArrayCoreMap's keySet iterator converts an ArrayIndexOutOfBoundsException from indexing past the internal keys array into a NoSuchElementException with this message. It is the standard Iterator contract: calling next() after the last key throws. The message is only a diagnostic rethrow, not a corruption indicator.
Solutions
- Use a for-each loop over coremap.keySet() instead of manual next() calls.
- Always check hasNext() before next().
- Avoid removing keys from the ArrayCoreMap while iterating over its key set.
- If index-based access is needed, bounds-check against size() first.
Example fix
// before
Iterator<Class<?>> it = map.keySet().iterator();
while (true) { process(it.next()); } // throws at end
// after
for (Class<?> key : map.keySet()) { process(key); } Defensive patterns
Strategy: try-catch
Try / catch
try { Class<?> k = it.next(); } catch (NoSuchElementException e) { /* iterator exhausted: normal end-of-iteration signal */ } Prevention
- Prefer for-each over manual iterator.next() calls.
- Never remove keys from an ArrayCoreMap while iterating its key set.
- Always pair next() with hasNext().
When it happens
Trigger: Calling next() on the keySet()/keyIterator() of an ArrayCoreMap after hasNext() would return false — i.e. iterating past the end, including concurrent modification that shrinks the map while iterating.
Common situations: Manual index-based loops over keys without checking i < size(); nested iteration that removes keys mid-loop; forgetting hasNext() when consuming the iterator directly.
Related errors
- DocumentIterator exhausted.
- Processed trees, but there are more trees and text is empty
- DocumentIterator exhausted.
- Graph edge iterator exhausted.
- ERROR: Sentences must instantiate Annotation!
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/e1b3e39ede96e118.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/util/ArrayCoreMap.java:178
public Set<Class<?>> keySet() {
return new AbstractSet<Class<?>>() {
@Override
public Iterator<Class<?>> iterator() {
return new Iterator<Class<?>>() {
private int i; // = 0;
@Override
public boolean hasNext() {
return i < size;
}
@Override
public Class<?> next() {
try {
return keys[i++];
} catch (ArrayIndexOutOfBoundsException aioobe) {
throw new NoSuchElementException("ArrayCoreMap keySet iterator exhausted");
}
}
@Override
@SuppressWarnings("unchecked")
public void remove() {
ArrayCoreMap.this.remove((Class) keys[i]);
}
};
}
@Override
public int size() {
return size;
}
};
}
View on GitHub (pinned to 1b7edd19c4)