didi/DoKit · error · IllegalArgumentException
Array has incompatible type: {}
Error message
Array has incompatible type: {} What it means
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.
Source
Thrown at Android/dokit-util/src/main/java/com/didichuxing/doraemonkit/util/LogUtils.java:1168
return Arrays.deepToString((Object[]) object);
} else if (object instanceof boolean[]) {
return Arrays.toString((boolean[]) object);
} else if (object instanceof byte[]) {
return Arrays.toString((byte[]) object);
} else if (object instanceof char[]) {
return Arrays.toString((char[]) object);
} else if (object instanceof double[]) {
return Arrays.toString((double[]) object);
} else if (object instanceof float[]) {
return Arrays.toString((float[]) object);
} else if (object instanceof int[]) {
return Arrays.toString((int[]) object);
} else if (object instanceof long[]) {
return Arrays.toString((long[]) object);
} else if (object instanceof short[]) {
return Arrays.toString((short[]) object);
}
throw new IllegalArgumentException("Array has incompatible type: " + object.getClass());
}
}
private static <T> Class getTypeClassFromParadigm(final IFormatter<T> formatter) {
Type[] genericInterfaces = formatter.getClass().getGenericInterfaces();
Type type;
if (genericInterfaces.length == 1) {
type = genericInterfaces[0];
} else {
type = formatter.getClass().getGenericSuperclass();
}
type = ((ParameterizedType) type).getActualTypeArguments()[0];
while (type instanceof ParameterizedType) {
type = ((ParameterizedType) type).getRawType();
}
String className = type.toString();
if (className.startsWith("class ")) {
className = className.substring(6);View on GitHub (pinned to 626827cddb)
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.
Example fix
// before
LogUtils.d("Matrix", weights); // weights is float[][] -> throws when formatted
// after
LogUtils.d("Matrix", java.util.Arrays.deepToString(weights)); Defensive patterns
Strategy: try-catch
Validate before calling
Object loggable = value != null && value.getClass().isArray()
&& !value.getClass().getComponentType().isArray()
? value : (value == null ? null : java.util.Arrays.deepToString((Object[]) value));
LogUtils.d(tag, loggable != null ? loggable : "null"); Type guard
static boolean isFlatArray(Object o) {
return o != null && o.getClass().isArray()
&& !o.getClass().getComponentType().isArray();
} Try / catch
try { LogUtils.d(tag, payload); } catch (IllegalArgumentException e) { LogUtils.d(tag, String.valueOf(payload)); } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Not an array: " + array.getClass()
- Array has incompatible type: " + array.getClass()
- Unsupported object type: " + object.getClass().getName()
- precision shouldn't be less than zero!
- The key is null.
AI-assisted analysis of didi/DoKit@626827cddb (2026-08-14).
Data as JSON: /api/errors/7349133f134acbbc.
Report an issue: GitHub.