{"record":{"id":"00dd0c2d611cec83","repo":"Blankj/AndroidUtilCode","slug":"array-has-incompatible-type","errorCode":null,"errorMessage":"Array has incompatible type: {}","messagePattern":"Array has incompatible type: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"lib/utilcode/src/main/java/com/blankj/utilcode/util/ArrayUtils.java","lineNumber":2137,"sourceCode":"            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);\n        } else if (array instanceof char[]) {\n            return Arrays.toString((char[]) array);\n        } else if (array instanceof double[]) {\n            return Arrays.toString((double[]) array);\n        } else if (array instanceof float[]) {\n            return Arrays.toString((float[]) array);\n        } else if (array instanceof int[]) {\n            return Arrays.toString((int[]) array);\n        } else if (array instanceof long[]) {\n            return Arrays.toString((long[]) array);\n        } else if (array instanceof short[]) {\n            return Arrays.toString((short[]) array);\n        }\n        throw new IllegalArgumentException(\"Array has incompatible type: \" + array.getClass());\n    }\n\n    public interface Closure<E> {\n        void execute(int index, E item);\n    }\n}\n","sourceCodeStart":2119,"sourceCodeEnd":2144,"githubUrl":"https://github.com/Blankj/AndroidUtilCode/blob/7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809/lib/utilcode/src/main/java/com/blankj/utilcode/util/ArrayUtils.java#L2119-L2144","documentation":"Thrown by ArrayUtils.toString when the argument is non-null but not one of the supported array types (Object[], boolean[], byte[], char[], short[], int[], long[], float[], double[]). The method dispatches on instanceof for each array kind and throws as a terminal fallback. null is handled separately (returns \"null\").","triggerScenarios":"Calling toString on a scalar Object (String, Integer, custom POJO) or a Collection instead of an array. The method is array-specific; it is not a general Object.toString replacement.","commonSituations":"Using ArrayUtils.toString as a generic debug printer for arbitrary objects; passing a List instead of list.toArray(); feeding boxed primitives from deserialized JSON.","solutions":["Use String.valueOf(obj) or obj.toString() for non-array objects.","Convert collections to arrays: ArrayUtils.toString(list.toArray()).","Add an isArray() guard and branch to a non-array path.","Prefer Arrays.toString / Arrays.deepToString directly when you already have a typed array."],"exampleFix":"// before\nString s = ArrayUtils.toString(\"hello\"); // Array has incompatible type: class String\n\n// after\nString s = (obj == null) ? \"null\" : obj.toString();","handlingStrategy":"type-guard","validationCode":"String s = (array == null)\n    ? \"null\"\n    : (array.getClass().isArray() ? ArrayUtils.toString(array) : String.valueOf(array));","typeGuard":"static boolean isArray(Object o) {\n    return o != null && o.getClass().isArray();\n}","tryCatchPattern":"try {\n    s = ArrayUtils.toString(obj);\n} catch (IllegalArgumentException e) {\n    s = String.valueOf(obj);\n}","preventionTips":["ArrayUtils.toString is array-only; use String.valueOf for scalars.","Convert collections to arrays before calling toString.","Branch on getClass().isArray() for polymorphic inputs."],"tags":["array","illegal-argument","type-mismatch","tostring","arrayutils","java"],"backgroundTag":null,"analyzedSha":"7b4caf9e5440046b3fefb63b6b6e2ead7ebaf809","analyzedAt":"2026-08-14T02:26:54.956Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}