{"record":{"id":"7ab04d2bc1bf3be3","repo":"Blankj/AndroidUtilCode","slug":"unsupported-object-type","errorCode":null,"errorMessage":"Unsupported object type: {}","messagePattern":"Unsupported object type: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/utilcode/src/main/java/com/blankj/utilcode/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/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/utilcode/src/main/java/com/blankj/utilcode/util/CollectionUtils.java#L731-L767","documentation":"Thrown by CollectionUtils.get(object, index) when the object is not a Map, List, Object[], Iterator, Collection, or Enumeration, and the fallback Array.get(object, index) raises IllegalArgumentException (the object is not array-like). The library wraps that into an 'Unsupported object type' message naming the class. It indicates the caller passed a scalar or otherwise non-indexable object.","triggerScenarios":"Calling get on a String, boxed primitive (Integer/Long), custom POJO, or any type that is neither a collection nor an array; passing an object whose runtime class changed from a collection to a scalar.","commonSituations":"Loosely-typed code paths where the object's type is unknown; deserializing JSON into a Map vs a scalar depending on payload; passing config values that may be a single object or a list.","solutions":["Branch on the object's type before calling get; handle scalars separately.","Normalize the input to a Collection/array (e.g., wrap a single scalar in a list) before indexing.","Use CollectionUtils.size(object) safely or check instanceof Collection/List first.","Tighten the API so only indexable types reach get()."],"exampleFix":"// before\nObject v = CollectionUtils.get(jsonValue, 0); // String -> Unsupported object type\n\n// after\nList<?> items = (jsonValue instanceof Collection)\n    ? new ArrayList<>((Collection<?>) jsonValue)\n    : Collections.singletonList(jsonValue);\nObject v = items.get(0);","handlingStrategy":"type-guard","validationCode":"if (object instanceof Map || object instanceof List || object instanceof Collection\n        || object instanceof Iterator || object instanceof Enumeration\n        || (object != null && object.getClass().isArray())) {\n    Object v = CollectionUtils.get(object, index);\n} else {\n    // scalar/non-indexable; handle separately\n}","typeGuard":"static boolean isIndexable(Object o) {\n    if (o == null) return false;\n    return o instanceof Map || o instanceof List || o instanceof Collection\n        || o instanceof Iterator || o instanceof Enumeration\n        || o.getClass().isArray();\n}","tryCatchPattern":"try {\n    v = CollectionUtils.get(object, index);\n} catch (IllegalArgumentException e) {\n    v = null; // unsupported object type\n}","preventionTips":["Branch on type before calling get; handle scalars explicitly.","Normalize single values into a one-element list before indexing.","Tighten loosely-typed APIs so only indexable types reach get()."],"tags":["collection","illegal-argument","type-mismatch","collectionutils","java"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}