{"record":{"id":"c785030f47f4e6ba","repo":"alibaba/arthas","slug":"source-is-not-an-array","errorCode":null,"errorMessage":"Source is not an array: {}","messagePattern":"Source is not an array: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/com/taobao/arthas/core/util/ObjectUtils.java","lineNumber":109,"sourceCode":"                    break;\n                }\n            } else if(candidate.toString().equalsIgnoreCase(constant)) {\n                break;\n            }\n\n            ++var5;\n        }\n\n        return true;\n    }\n\n    public static Object[] toObjectArray(Object source) {\n        if(source instanceof Object[]) {\n            return (Object[])((Object[])source);\n        } else if(source == null) {\n            return new Object[0];\n        } else if(!source.getClass().isArray()) {\n            throw new IllegalArgumentException(\"Source is not an array: \" + source);\n        } else {\n            int length = Array.getLength(source);\n            if(length == 0) {\n                return new Object[0];\n            } else {\n                Class wrapperType = Array.get(source, 0).getClass();\n                Object[] newArray = (Object[])((Object[])Array.newInstance(wrapperType, length));\n\n                for(int i = 0; i < length; ++i) {\n                    newArray[i] = Array.get(source, i);\n                }\n\n                return newArray;\n            }\n        }\n    }\n\n    public static boolean nullSafeEquals(Object o1, Object o2) {","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/core/src/main/java/com/taobao/arthas/core/util/ObjectUtils.java#L91-L127","documentation":"ObjectUtils.toObjectArray() throws IllegalArgumentException when the source object is non-null, is not already an Object[], and is not recognized by Class.isArray() as any kind of array. The method's contract is to convert primitive or object arrays into Object[]; a non-array object violates that precondition.","triggerScenarios":"Calling toObjectArray(source) where source is a Collection, Map, String, or any plain object rather than an actual Java array (int[], Object[], etc.).","commonSituations":"A caller passed a List or Set expecting array conversion; a generic code path received a boxed scalar or string and forwarded it here; the method is used as a utility without checking the input type first.","solutions":["Convert the Collection to an array before calling: list.toArray() instead of passing the list directly.","Add an instanceof check before calling toObjectArray and handle non-array inputs separately.","If the input may legitimately be non-array, guard with source.getClass().isArray() and branch."],"exampleFix":"// before\nList<String> items = Arrays.asList(\"a\", \"b\");\nObject[] arr = ObjectUtils.toObjectArray(items); // throws\n\n// after\nObject[] arr = items.toArray();\n// or, if you must route through toObjectArray:\nObject[] arr = items.toArray(new Object[0]);","handlingStrategy":"type-guard","validationCode":"Object source = getValue();\nif (source == null || !source.getClass().isArray()) {\n    // handle non-array: convert collection, or return empty\n    return new Object[0];\n}\nObjectUtils.toObjectArray(source);","typeGuard":"public static boolean isArray(Object o) {\n    return o != null && o.getClass().isArray();\n}","tryCatchPattern":"try {\n    arr = ObjectUtils.toObjectArray(source);\n} catch (IllegalArgumentException e) {\n    if (source instanceof Collection) {\n        arr = ((Collection<?>) source).toArray();\n    } else {\n        arr = new Object[]{source};\n    }\n}","preventionTips":["Check source.getClass().isArray() before calling toObjectArray.","Convert Collections via toArray() instead of routing through toObjectArray."],"tags":["arthas","reflection","type-check","utility"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}