alibaba/arthas · error · IllegalArgumentException
{iface} missing newInstance method
Error message
{iface} missing newInstance method What it means
Thrown by ReflectUtils.findNewInstance when the supplied interface's single declared method is NOT named 'newInstance'. findNewInstance first resolves the interface's sole method via findInterfaceMethod, then asserts the method name equals 'newInstance' — this assert fails. It is a CGLib-style factory-interface contract: the interface is expected to declare exactly one factory method named newInstance.
Source
Thrown at common/src/main/java/com/taobao/arthas/common/ReflectUtils.java:314
String[] names = new String[classes.length];
for (int i = 0; i < names.length; i++) {
names[i] = classes[i].getName();
}
return names;
}
public static Class[] getClasses(Object[] objects) {
Class[] classes = new Class[objects.length];
for (int i = 0; i < objects.length; i++) {
classes[i] = objects[i].getClass();
}
return classes;
}
public static Method findNewInstance(Class iface) {
Method m = findInterfaceMethod(iface);
if (!m.getName().equals("newInstance")) {
throw new IllegalArgumentException(iface + " missing newInstance method");
}
return m;
}
public static Method[] getPropertyMethods(PropertyDescriptor[] properties, boolean read, boolean write) {
Set methods = new HashSet();
for (int i = 0; i < properties.length; i++) {
PropertyDescriptor pd = properties[i];
if (read) {
methods.add(pd.getReadMethod());
}
if (write) {
methods.add(pd.getWriteMethod());
}
}
methods.remove(null);
return (Method[]) methods.toArray(new Method[methods.size()]);
}View on GitHub (pinned to 21cf2e9ba5)
Solutions
- Pass a single-method interface whose method is literally named 'newInstance' (the CGLib Factory convention).
- If you only need to invoke the interface's method, call findInterfaceMethod(iface) directly instead of findNewInstance.
- If you need a generic single-method invoker, write your own helper that resolves the declared method without the newInstance name check.
Example fix
// before Method m = ReflectUtils.findNewInstance(MyFactory.class); // MyFactory has create() // after (use the generic interface-method resolver) Method m = ReflectUtils.findInterfaceMethod(MyFactory.class); // or rename MyFactory's method to newInstance
Defensive patterns
Strategy: validation
Validate before calling
Method sole = iface.isInterface() && iface.getDeclaredMethods().length == 1 ? iface.getDeclaredMethods()[0] : null;
if (sole == null || !"newInstance".equals(sole.getName())) {
// do not call ReflectUtils.findNewInstance(iface); pick another path
} Type guard
static boolean isFactoryInterface(Class<?> iface) {
if (iface == null || !iface.isInterface()) return false;
Method[] ms = iface.getDeclaredMethods();
return ms.length == 1 && "newInstance".equals(ms[0].getName());
} Prevention
- Only pass CGLib-style single-method interfaces whose method is named newInstance.
- Prefer findInterfaceMethod for generic single-method resolution without the name check.
- Document at call sites that findNewInstance implies the newInstance naming contract.
When it happens
Trigger: Call ReflectUtils.findNewInstance(iface) where iface is a single-method interface but its method has any name other than 'newInstance' (e.g. a Supplier, Callable, or custom factory interface with methods like create/build/apply).
Common situations: Passing a Java standard functional interface (Supplier, Function, Consumer) or a user-defined factory interface to a code path that expects a CGLib Factory/newInstance interface. Using ReflectUtils as a generic reflection helper when it was written specifically for cglib Enhancer factory generation.
Related errors
- {iface} is not an interface
- expecting exactly 1 method in {iface}
- Required parameter '{paramName}' cannot be empty
- Cannot convert to char: {value}
- SessionId is required for this operation
AI-assisted analysis of alibaba/arthas@21cf2e9ba5 (2026-08-14).
Data as JSON: /api/errors/83a3971f65b411cf.
Report an issue: GitHub.