{"record":{"id":"d16d89520c4f26b4","repo":"alibaba/nacos","slug":"unsupported-object-type-null","errorCode":null,"errorMessage":"Unsupported object type: null","messagePattern":"Unsupported object type: null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"common/src/main/java/com/alibaba/nacos/common/utils/CollectionUtils.java","lineNumber":196,"sourceCode":"     * Judge whether object is empty.\n     *\n     * @param object object\n     * @return true if object is empty, otherwise false\n     * @throws IllegalArgumentException if object has no length or size\n     */\n    public static boolean sizeIsEmpty(Object object) {\n        if (object instanceof Collection) {\n            return ((Collection) object).isEmpty();\n        } else if (object instanceof Map) {\n            return ((Map) object).isEmpty();\n        } else if (object instanceof Object[]) {\n            return ((Object[]) object).length == 0;\n        } else if (object instanceof Iterator) {\n            return ((Iterator) object).hasNext() == false;\n        } else if (object instanceof Enumeration) {\n            return ((Enumeration) object).hasMoreElements() == false;\n        } else if (object == null) {\n            throw new IllegalArgumentException(\"Unsupported object type: null\");\n        } else {\n            try {\n                return Array.getLength(object) == 0;\n            } catch (IllegalArgumentException ex) {\n                throw new IllegalArgumentException(\n                    \"Unsupported object type: \" + object.getClass().getName());\n            }\n        }\n    }\n    \n    /**\n     * Whether contain item in collection.\n     *\n     * @param coll   collection\n     * @param target target value\n     * @param <T>    General Type\n     * @return true if contain, otherwise false\n     */","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/alibaba/nacos/blob/9b989acdf181d00898f2e8839257bb2b2a3cefe3/common/src/main/java/com/alibaba/nacos/common/utils/CollectionUtils.java#L178-L214","documentation":"Thrown by CollectionUtils.sizeIsEmpty(Object) when the argument is null. Unlike most 'isEmpty' helpers, this method deliberately rejects null instead of treating it as empty — passing null is treated as a programming error, not an empty collection.","triggerScenarios":"Calling CollectionUtils.sizeIsEmpty(null). Any caller that passes an unguarded null variable hits this immediately.","commonSituations":"A nullable field or method result passed into sizeIsEmpty without a null check; refactoring that introduced a nullable return upstream.","solutions":["Null-check before calling: if (obj != null && sizeIsEmpty(obj)) ...","Prefer CollectionUtils.isEmpty(coll) / isNotEmpty(coll) for null-safe behavior when you only deal with Collections.","Fix the upstream null return so the invariant the method assumes holds."],"exampleFix":"// before\nboolean empty = CollectionUtils.sizeIsEmpty(maybeNull);\n\n// after\nboolean empty = maybeNull != null && CollectionUtils.sizeIsEmpty(maybeNull);","handlingStrategy":"validation","validationCode":"if (object == null) {\n    // treat as empty or reject explicitly — sizeIsEmpty will not accept null\n    return; // or throw a domain error\n}\nboolean empty = CollectionUtils.sizeIsEmpty(object);","typeGuard":"boolean isSizeable(Object o) {\n    return o instanceof Collection || o instanceof Map\n        || o instanceof Object[] || o instanceof Iterator\n        || o instanceof Enumeration;\n}","tryCatchPattern":null,"preventionTips":["Never call sizeIsEmpty on a possibly-null value without a null guard.","Prefer CollectionUtils.isEmpty(coll) for null-safe Collection checks.","Fix upstream null returns at the source."],"tags":["collections","null-check","validation","utility"],"backgroundTag":null,"analyzedSha":"9b989acdf181d00898f2e8839257bb2b2a3cefe3","analyzedAt":"2026-08-14T07:17:31.569Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}