{"record":{"id":"7349133f134acbbc","repo":"didi/DoKit","slug":"array-has-incompatible-type","errorCode":null,"errorMessage":"Array has incompatible type: {}","messagePattern":"Array has incompatible type: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Android/dokit-util/src/main/java/com/didichuxing/doraemonkit/util/LogUtils.java","lineNumber":1168,"sourceCode":"                return Arrays.deepToString((Object[]) object);\n            } else if (object instanceof boolean[]) {\n                return Arrays.toString((boolean[]) object);\n            } else if (object instanceof byte[]) {\n                return Arrays.toString((byte[]) object);\n            } else if (object instanceof char[]) {\n                return Arrays.toString((char[]) object);\n            } else if (object instanceof double[]) {\n                return Arrays.toString((double[]) object);\n            } else if (object instanceof float[]) {\n                return Arrays.toString((float[]) object);\n            } else if (object instanceof int[]) {\n                return Arrays.toString((int[]) object);\n            } else if (object instanceof long[]) {\n                return Arrays.toString((long[]) object);\n            } else if (object instanceof short[]) {\n                return Arrays.toString((short[]) object);\n            }\n            throw new IllegalArgumentException(\"Array has incompatible type: \" + object.getClass());\n        }\n    }\n\n    private static <T> Class getTypeClassFromParadigm(final IFormatter<T> formatter) {\n        Type[] genericInterfaces = formatter.getClass().getGenericInterfaces();\n        Type type;\n        if (genericInterfaces.length == 1) {\n            type = genericInterfaces[0];\n        } else {\n            type = formatter.getClass().getGenericSuperclass();\n        }\n        type = ((ParameterizedType) type).getActualTypeArguments()[0];\n        while (type instanceof ParameterizedType) {\n            type = ((ParameterizedType) type).getRawType();\n        }\n        String className = type.toString();\n        if (className.startsWith(\"class \")) {\n            className = className.substring(6);","sourceCodeStart":1150,"sourceCodeEnd":1186,"githubUrl":"https://github.com/didi/DoKit/blob/626827cddb2feb2f3aee87a52a064b4e5ca2bed4/Android/dokit-util/src/main/java/com/didichuxing/doraemonkit/util/LogUtils.java#L1150-L1186","documentation":"LogUtils' internal element formatter stringifies array objects passed to the logger; after the same instanceof chain over boolean[]...short[] and Object[] fails, it throws IllegalArgumentException('Array has incompatible type: <class>'). Nested arrays (int[][]) and unsupported component types are the usual culprits, and the exception is thrown from inside the logging pipeline, so it can crash an app merely because a log statement was added.","triggerScenarios":"Calling LogUtils.d(tag, int[][]) or logging an object graph whose toString delegation reaches this formatter with a 2D array; the throw happens during formatting, i.e. only when that log level is enabled.","commonSituations":"Debug logging added late in development that only runs at verbose level (so it survives testing); matrix/byte-buffer data structures; enabling verbose logs in production via a remote switch and crashing on data shapes never tested.","solutions":["Pre-format such values yourself before logging: Arrays.deepToString(grid) or Arrays.toString(flattened).","Do not pass multidimensional or exotic arrays directly to LogUtils.","Test with the actual log level enabled before shipping logging of complex payloads."],"exampleFix":"// before\nLogUtils.d(\"Matrix\", weights); // weights is float[][] -> throws when formatted\n\n// after\nLogUtils.d(\"Matrix\", java.util.Arrays.deepToString(weights));","handlingStrategy":"try-catch","validationCode":"Object loggable = value != null && value.getClass().isArray()\n        && !value.getClass().getComponentType().isArray()\n        ? value : (value == null ? null : java.util.Arrays.deepToString((Object[]) value));\nLogUtils.d(tag, loggable != null ? loggable : \"null\");","typeGuard":"static boolean isFlatArray(Object o) {\n    return o != null && o.getClass().isArray()\n            && !o.getClass().getComponentType().isArray();\n}","tryCatchPattern":"try { LogUtils.d(tag, payload); } catch (IllegalArgumentException e) { LogUtils.d(tag, String.valueOf(payload)); }","preventionTips":["Pre-stringify complex payloads with Arrays.deepToString/toString before logging.","Test with verbose logging enabled before shipping; log-level-gated crashes evade CI.","Wrap debug logging of arbitrary objects in a safe-format helper."],"tags":["logging","arrays","illegal-argument"],"backgroundTag":null,"analyzedSha":"626827cddb2feb2f3aee87a52a064b4e5ca2bed4","analyzedAt":"2026-08-14T12:45:58.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}