Blankj/AndroidUtilCode · error · IndexOutOfBoundsException
Entry does not exist: {}
Error message
Entry does not exist: {} What it means
Thrown by CollectionUtils.get when the object is an Iterator (or a Map/Collection, which are reduced to an iterator) and the iterator is exhausted before the requested index is reached. Note the index is decremented during iteration, so the reported value is the residual count (<= 0), not the original index. Map entries are indexed via their entrySet iterator.
Source
Thrown at lib/utilcode/src/main/java/com/blankj/utilcode/util/CollectionUtils.java:730
if (object instanceof Map) {
Map map = (Map) object;
Iterator iterator = map.entrySet().iterator();
return get(iterator, index);
} else if (object instanceof List) {
return ((List) object).get(index);
} else if (object instanceof Object[]) {
return ((Object[]) object)[index];
} else if (object instanceof Iterator) {
Iterator it = (Iterator) object;
while (it.hasNext()) {
index--;
if (index == -1) {
return it.next();
} else {
it.next();
}
}
throw new IndexOutOfBoundsException("Entry does not exist: " + index);
} else if (object instanceof Collection) {
Iterator iterator = ((Collection) object).iterator();
return get(iterator, index);
} else if (object instanceof Enumeration) {
Enumeration it = (Enumeration) object;
while (it.hasMoreElements()) {
index--;
if (index == -1) {
return it.nextElement();
} else {
it.nextElement();
}
}
throw new IndexOutOfBoundsException("Entry does not exist: " + index);
} else {
try {
return Array.get(object, index);
} catch (IllegalArgumentException ex) {View on GitHub (pinned to 7b4caf9e54)
Solutions
- Bound the index against the known size before calling get (index < size).
- For positional access prefer a List (uses List.get directly) over a Map/Iterator.
- Do not reuse a one-shot Iterator across multiple get() calls; obtain a fresh iterator each time.
- For Map access, use the key directly instead of a positional index.
Example fix
// before Object v = CollectionUtils.get(map, map.size()); // Entry does not exist // after Object v = CollectionUtils.get(map, map.size() - 1); // last valid index
Defensive patterns
Strategy: validation
Validate before calling
int size = CollectionUtils.size(object);
if (index >= 0 && index < size) {
Object v = CollectionUtils.get(object, index);
} else {
// index past the end of an iterator-backed collection
} Try / catch
try {
v = CollectionUtils.get(object, index);
} catch (IndexOutOfBoundsException e) {
v = null; // iterator exhausted before index
} Prevention
- Bound the index against size() before calling get on Map/Collection/Iterator.
- Prefer List.get for positional access; reserve get() for genuinely unknown types.
- Never reuse a one-shot Iterator across multiple get() calls.
When it happens
Trigger: Calling get on a Map/Collection/Iterator with an index >= the number of available elements; iterating a one-shot Iterator that had already been partially consumed before the call.
Common situations: Assuming a Map's position matches insertion order without an ordered map; requesting an index larger than size(); reusing a Stream/Iterator that has already advanced; off-by-one when index equals size().
Related errors
- Index cannot be negative: {}
- Unsupported object type: {}
- Index: {}, array1 Length: {}
- Index: {}, Length: 0
- Index: {}, Length: {}
AI-assisted analysis of Blankj/AndroidUtilCode@7b4caf9e54 (2026-08-14).
Data as JSON: /api/errors/f1186414bc5f77b9.
Report an issue: GitHub.