{"record":{"id":"20853738e4be524d","repo":"Blankj/AndroidUtilCode","slug":"not-an-array","errorCode":null,"errorMessage":"Not an array: {}","messagePattern":"Not an array: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/utilcode/src/main/java/com/blankj/utilcode/util/ArrayUtils.java","lineNumber":2105,"sourceCode":"            long[] longs = (long[]) array;\n            for (int i = 0, length = longs.length; i < length; i++) {\n                long ele = longs[i];\n                closure.execute(i, (E) Long.valueOf(ele));\n            }\n        } else if (array instanceof float[]) {\n            float[] floats = (float[]) array;\n            for (int i = 0, length = floats.length; i < length; i++) {\n                float ele = floats[i];\n                closure.execute(i, (E) Float.valueOf(ele));\n            }\n        } else if (array instanceof double[]) {\n            double[] doubles = (double[]) array;\n            for (int i = 0, length = doubles.length; i < length; i++) {\n                double ele = doubles[i];\n                closure.execute(i, (E) Double.valueOf(ele));\n            }\n        } else {\n            throw new IllegalArgumentException(\"Not an array: \" + array.getClass());\n        }\n    }\n\n    /**\n     * Return the string of array.\n     *\n     * @param array The array.\n     * @return the string of array\n     */\n    @NonNull\n    public static String toString(@Nullable Object array) {\n        if (array == null) return \"null\";\n        if (array instanceof Object[]) {\n            return Arrays.deepToString((Object[]) array);\n        } else if (array instanceof boolean[]) {\n            return Arrays.toString((boolean[]) array);\n        } else if (array instanceof byte[]) {\n            return Arrays.toString((byte[]) array);","sourceCodeStart":2087,"sourceCodeEnd":2123,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/utilcode/src/main/java/com/blankj/utilcode/util/ArrayUtils.java#L2087-L2123","documentation":"Thrown by ArrayUtils.forAllDo when the first argument is non-null but is not one of the recognized array types (Object[], boolean[], byte[], char[], short[], int[], long[], float[], double[]). The method iterates the closure over each element; null and null closure return early (line 2049), so reaching this throw means a non-array object was passed.","triggerScenarios":"Passing a Collection (List, Set), a Map, a String, a boxed primitive, or any POJO to forAllDo instead of a real array. Also triggered by passing a multi-dimensional array component that is itself a non-iterable scalar.","commonSituations":"Confusing forAllDo with CollectionUtils.forEach; passing list.toArray() incorrectly (e.g., a single element instead of the array); reflective code feeding an arbitrary Object into forAllDo.","solutions":["Convert collections to arrays first: forAllDo(list.toArray(), closure).","Use CollectionUtils.forEach for Collection/Iterator/Map inputs.","Add an isArray() type guard before calling forAllDo.","If the value may be null, let it pass through (null is handled gracefully); only non-array non-null values fail."],"exampleFix":"// before\nArrayUtils.forAllDo(new ArrayList<>(), closure); // Not an array: class ArrayList\n\n// after\nArrayUtils.forAllDo(list.toArray(), closure);","handlingStrategy":"type-guard","validationCode":"if (array != null && array.getClass().isArray()) {\n    ArrayUtils.forAllDo(array, closure);\n} else if (array instanceof Collection) {\n    ArrayUtils.forAllDo(((Collection<?>) array).toArray(), closure);\n}","typeGuard":"static boolean isArray(Object o) {\n    return o != null && o.getClass().isArray();\n}","tryCatchPattern":"try {\n    ArrayUtils.forAllDo(obj, closure);\n} catch (IllegalArgumentException e) {\n    if (obj instanceof Collection) ArrayUtils.forAllDo(((Collection<?>) obj).toArray(), closure);\n}","preventionTips":["forAllDo only accepts real arrays; convert collections via toArray() first.","Use CollectionUtils.forEach for non-array iterables.","Guard with getClass().isArray() when the input type is unknown."],"tags":["array","illegal-argument","type-mismatch","closure","arrayutils","java"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}