{"record":{"id":"4693f75a3d65b985","repo":"chinabugotech/hutool","slug":"unsupported-object-type-classname","errorCode":null,"errorMessage":"Unsupported object type: {className}","messagePattern":"Unsupported object type: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java","lineNumber":3170,"sourceCode":"\t\tint total = 0;\n\t\tif (object instanceof Map<?, ?>) {\n\t\t\ttotal = ((Map<?, ?>) object).size();\n\t\t} else if (object instanceof Collection<?>) {\n\t\t\ttotal = ((Collection<?>) object).size();\n\t\t} else if (object instanceof Iterable<?>) {\n\t\t\ttotal = IterUtil.size((Iterable<?>) object);\n\t\t} else if (object instanceof Iterator<?>) {\n\t\t\ttotal = IterUtil.size((Iterator<?>) object);\n\t\t} else if (object instanceof Enumeration<?>) {\n\t\t\tfinal Enumeration<?> it = (Enumeration<?>) object;\n\t\t\twhile (it.hasMoreElements()) {\n\t\t\t\ttotal++;\n\t\t\t\tit.nextElement();\n\t\t\t}\n\t\t} else if (ArrayUtil.isArray(object)) {\n\t\t\ttotal = ArrayUtil.length(object);\n\t\t} else {\n\t\t\tthrow new IllegalArgumentException(\"Unsupported object type: \" + object.getClass().getName());\n\t\t}\n\t\treturn total;\n\t}\n\n\t/**\n\t * 判断两个{@link Collection} 是否元素和顺序相同，返回{@code true}的条件是：\n\t * <ul>\n\t *     <li>两个{@link Collection}必须长度相同</li>\n\t *     <li>两个{@link Collection}元素相同index的对象必须equals，满足{@link Objects#equals(Object, Object)}</li>\n\t * </ul>\n\t * 此方法来自Apache-Commons-Collections4。\n\t *\n\t * @param list1 列表1\n\t * @param list2 列表2\n\t * @return 是否相同\n\t * @since 5.6.0\n\t */\n\tpublic static boolean isEqualList(final Collection<?> list1, final Collection<?> list2) {","sourceCodeStart":3152,"sourceCodeEnd":3188,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java#L3152-L3188","documentation":"Thrown by CollUtil.size(Object object) when the object is not one of the supported size-measurable types: Map, Collection, Iterable, Iterator, Enumeration, or array. Any other object type (String, Integer, custom POJO, etc.) is rejected. The method is a polymorphic size calculator with a bounded set of accepted types.","triggerScenarios":"Calling CollUtil.size(\"hello\"), CollUtil.size(42), CollUtil.size(somePojo), or any object that is not a Map, Collection, Iterable, Iterator, Enumeration, or array. Passing null returns 0 (no error).","commonSituations":"Passing a String to size() expecting character count (use StrUtil.length instead). Passing a primitive wrapper or custom object. Using size() as a generic 'get length' utility without knowing its type restrictions. Confusing CollUtil.size() with other size methods.","solutions":["Check the object type before calling size(), or use type-specific size methods.","For String length use StrUtil.length() or String.length().","For Map use map.size(), for Collection use collection.size(), for arrays use ArrayUtil.length().","If the object may be any of the supported types, guard with instanceof checks before calling."],"exampleFix":"// before\nint len = CollUtil.size(\"hello world\"); // throws — String not supported\n\n// after\nint len = StrUtil.length(\"hello world\"); // correct for strings\n// or for mixed types:\nif (object instanceof Collection<?>) {\n    size = ((Collection<?>) object).size();\n} else if (object instanceof Map<?, ?>) {\n    size = ((Map<?, ?>) object).size();\n}","handlingStrategy":"type-guard","validationCode":"if (object instanceof Collection<?>) {\n    return ((Collection<?>) object).size();\n} else if (object instanceof Map<?, ?>) {\n    return ((Map<?, ?>) object).size();\n} else if (object == null) {\n    return 0;\n}","typeGuard":"public static boolean isSizeable(Object obj) {\n    return obj == null || obj instanceof Map<?, ?> || obj instanceof Collection<?>\n        || obj instanceof Iterable<?> || obj instanceof Iterator<?>\n        || obj instanceof Enumeration<?> || ArrayUtil.isArray(obj);\n}","tryCatchPattern":null,"preventionTips":["Use type-specific size methods: String.length(), Map.size(), Collection.size().","Check instanceof before calling CollUtil.size() on unknown types.","Do not use CollUtil.size() as a generic length utility for all objects."],"tags":["collection","size","unsupported-type","input-validation"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}