{"record":{"id":"29fa658670614f8d","repo":"didi/DoKit","slug":"unsupported-object-type-object-getclass-get","errorCode":null,"errorMessage":"Unsupported object type: \" + object.getClass().getName()","messagePattern":"Unsupported object type: \" \\+ object\\.getClass\\(\\)\\.getName\\(\\)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Android/dokit-util/src/main/java/com/didichuxing/doraemonkit/util/CollectionUtils.java","lineNumber":749,"sourceCode":"        } else if (object instanceof Collection) {\n            Iterator iterator = ((Collection) object).iterator();\n            return get(iterator, index);\n        } else if (object instanceof Enumeration) {\n            Enumeration it = (Enumeration) object;\n            while (it.hasMoreElements()) {\n                index--;\n                if (index == -1) {\n                    return it.nextElement();\n                } else {\n                    it.nextElement();\n                }\n            }\n            throw new IndexOutOfBoundsException(\"Entry does not exist: \" + index);\n        } else {\n            try {\n                return Array.get(object, index);\n            } catch (IllegalArgumentException ex) {\n                throw new IllegalArgumentException(\"Unsupported object type: \" + object.getClass().getName());\n            }\n        }\n    }\n\n    /**\n     * Gets the size of the collection/iterator specified.\n     * <p>\n     * This method can handles objects as follows\n     * <ul>\n     * <li>Collection - the collection size\n     * <li>Map - the map size\n     * <li>Array - the array size\n     * <li>Iterator - the number of elements remaining in the iterator\n     * <li>Enumeration - the number of elements remaining in the enumeration\n     * </ul>\n     *\n     * @param object the object to get the size of\n     * @return the size of the specified collection","sourceCodeStart":731,"sourceCodeEnd":767,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit-util/src/main/java/com/didichuxing/doraemonkit/util/CollectionUtils.java#L731-L767","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nObject first = CollectionUtils.get(jsonResult, 0); // throws if jsonResult is a JSONObject-like Map is fine, but a scalar throws\n\n// after\nif (jsonResult instanceof List || jsonResult instanceof Object[]\n        || (jsonResult != null && jsonResult.getClass().isArray())) {\n    Object first = CollectionUtils.get(jsonResult, 0);\n} else {\n    Object first = jsonResult; // scalar: it IS the value\n}","handlingStrategy":"type-guard","validationCode":"static boolean isGettable(Object o) {\n    return o instanceof Map || o instanceof List || o instanceof Collection\n            || o instanceof Iterator || o instanceof Enumeration\n            || o instanceof Object[] || (o != null && o.getClass().isArray());\n}","typeGuard":"static boolean isGettable(Object o) {\n    return o instanceof Map || o instanceof Collection || o instanceof Iterator\n            || o instanceof Enumeration || o instanceof Object[]\n            || (o != null && o.getClass().isArray());\n}","tryCatchPattern":"try { v = CollectionUtils.get(o, i); } catch (IllegalArgumentException e) { v = o instanceof List ? ((List<?>) o).get(i) : null; }","preventionTips":["Verify the runtime type of deserialized data before generic get() calls.","Keep a whitelist of supported container types in generic layers."],"tags":["collections","illegal-argument","reflection"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}