didi/DoKit · error · IllegalArgumentException
Unsupported object type: " + object.getClass().getName()
Error message
Unsupported object type: " + object.getClass().getName()
What it means
The final else branch of CollectionUtils.get tries reflective java.lang.reflect.Array.get(object, index); if the object is not an array at all, Array.get throws IllegalArgumentException, which this code catches and rethrows as IllegalArgumentException('Unsupported object type: ' + className). So the input matched none of Map/List/Object[]/Iterator/Collection/Enumeration and is not a reflective array (e.g. a primitive array like int[] handled here, or a plain POJO).
Source
Thrown at Android/dokit-util/src/main/java/com/didichuxing/doraemonkit/util/CollectionUtils.java:749
} 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) {
throw new IllegalArgumentException("Unsupported object type: " + object.getClass().getName());
}
}
}
/**
* Gets the size of the collection/iterator specified.
* <p>
* This method can handles objects as follows
* <ul>
* <li>Collection - the collection size
* <li>Map - the map size
* <li>Array - the array size
* <li>Iterator - the number of elements remaining in the iterator
* <li>Enumeration - the number of elements remaining in the enumeration
* </ul>
*
* @param object the object to get the size of
* @return the size of the specified collectionView on GitHub (pinned to 626827cddb)
Solutions
- Validate the container type before calling: accept only Map, List, Object[], Iterator, Collection, Enumeration or isArray() values.
- Fix the data source so it produces the expected container type (e.g. correct JSON generic type when parsing).
- Wrap the call in try/catch(IllegalArgumentException) and fall back to treating the object as a scalar.
Example fix
// before
Object first = CollectionUtils.get(jsonResult, 0); // throws if jsonResult is a JSONObject-like Map is fine, but a scalar throws
// after
if (jsonResult instanceof List || jsonResult instanceof Object[]
|| (jsonResult != null && jsonResult.getClass().isArray())) {
Object first = CollectionUtils.get(jsonResult, 0);
} else {
Object first = jsonResult; // scalar: it IS the value
} Defensive patterns
Strategy: type-guard
Validate before calling
static boolean isGettable(Object o) {
return o instanceof Map || o instanceof List || o instanceof Collection
|| o instanceof Iterator || o instanceof Enumeration
|| o instanceof Object[] || (o != null && o.getClass().isArray());
} Type guard
static boolean isGettable(Object o) {
return o instanceof Map || o instanceof Collection || o instanceof Iterator
|| o instanceof Enumeration || o instanceof Object[]
|| (o != null && o.getClass().isArray());
} Try / catch
try { v = CollectionUtils.get(o, i); } catch (IllegalArgumentException e) { v = o instanceof List ? ((List<?>) o).get(i) : null; } Prevention
- Verify the runtime type of deserialized data before generic get() calls.
- Keep a whitelist of supported container types in generic layers.
When it happens
Trigger: Calling get on a String, a POJO, an Optional, or any custom object; primitive arrays actually work via Array.get, so the throw means the object is genuinely non-array and non-container.
Common situations: Generic 'get element at index' helpers fed with boxed values after a refactor; JSON deserialization producing LinkedHashMap where a List was expected; passing a CharSequence where the code assumed a collection.
Related errors
- Not an array: " + array.getClass()
- Array has incompatible type: " + array.getClass()
- Index cannot be negative: " + index
- Entry does not exist: " + index
- precision shouldn't be less than zero!
AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14).
Data as JSON: /api/errors/29fa658670614f8d.
Report an issue: GitHub.