alibaba/arthas · error · IllegalArgumentException
Source is not an array: {}
Error message
Source is not an array: {} What it means
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.
Source
Thrown at core/src/main/java/com/taobao/arthas/core/util/ObjectUtils.java:109
break;
}
} else if(candidate.toString().equalsIgnoreCase(constant)) {
break;
}
++var5;
}
return true;
}
public static Object[] toObjectArray(Object source) {
if(source instanceof Object[]) {
return (Object[])((Object[])source);
} else if(source == null) {
return new Object[0];
} else if(!source.getClass().isArray()) {
throw new IllegalArgumentException("Source is not an array: " + source);
} else {
int length = Array.getLength(source);
if(length == 0) {
return new Object[0];
} else {
Class wrapperType = Array.get(source, 0).getClass();
Object[] newArray = (Object[])((Object[])Array.newInstance(wrapperType, length));
for(int i = 0; i < length; ++i) {
newArray[i] = Array.get(source, i);
}
return newArray;
}
}
}
public static boolean nullSafeEquals(Object o1, Object o2) {View on GitHub (pinned to 21cf2e9ba5)
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.
Example fix
// before
List<String> items = Arrays.asList("a", "b");
Object[] arr = ObjectUtils.toObjectArray(items); // throws
// after
Object[] arr = items.toArray();
// or, if you must route through toObjectArray:
Object[] arr = items.toArray(new Object[0]); Defensive patterns
Strategy: type-guard
Validate before calling
Object source = getValue();
if (source == null || !source.getClass().isArray()) {
// handle non-array: convert collection, or return empty
return new Object[0];
}
ObjectUtils.toObjectArray(source); Type guard
public static boolean isArray(Object o) {
return o != null && o.getClass().isArray();
} Try / catch
try {
arr = ObjectUtils.toObjectArray(source);
} catch (IllegalArgumentException e) {
if (source instanceof Collection) {
arr = ((Collection<?>) source).toArray();
} else {
arr = new Object[]{source};
}
} Prevention
- Check source.getClass().isArray() before calling toObjectArray.
- Convert Collections via toArray() instead of routing through toObjectArray.
When it happens
Trigger: Calling toObjectArray(source) where source is a Collection, Map, String, or any plain object rather than an actual Java array (int[], Object[], etc.).
Common situations: 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.
Related errors
- {iface} is not an interface
- model class is null
- create view instance failure, viewClass:{}
- Couldn't find rpcmethod: {}
- Arthas server port binding failed! Please check $HOME/logs/a
AI-assisted analysis of alibaba/arthas@21cf2e9ba5 (2026-08-14).
Data as JSON: /api/errors/c785030f47f4e6ba.
Report an issue: GitHub.