apache/dubbo · error · IllegalStateException
cannot find method %s,class: %s
Error message
cannot find method %s,class: %s
What it means
MethodUtils.invokeMethod resolves a method by name and the runtime types of the supplied arguments via findMethod. If no method with that name and matching parameter types exists on the class, it throws IllegalStateException.
Source
Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/utils/MethodUtils.java:288
/**
* Invoke the target object and method
*
* @param object the target object
* @param methodName the method name
* @param methodParameters the method parameters
* @param <T> the return type
* @return the target method's execution result
* @since 2.7.6
*/
static <T> T invokeMethod(Object object, String methodName, Object... methodParameters) {
Class type = object.getClass();
Class[] parameterTypes = resolveTypes(methodParameters);
Method method = findMethod(type, methodName, parameterTypes);
T value = null;
if (method == null) {
throw new IllegalStateException(
String.format("cannot find method %s,class: %s", methodName, type.getName()));
}
try {
final boolean isAccessible = method.isAccessible();
if (!isAccessible) {
method.setAccessible(true);
}
value = (T) method.invoke(object, methodParameters);
method.setAccessible(isAccessible);
} catch (Exception e) {
throw new IllegalArgumentException(e);
}
return value;
}
View on GitHub (pinned to 3a3043227f)
Solutions
- Confirm the method name and the exact parameter types against the target class
- Pass typed arguments (cast nulls to the expected Class) so resolveTypes picks the right overload
- If the method is on an interface, ensure target is an instance of that interface
- Prefer a direct typed call or a Method handle instead of name-based reflection where possible
Example fix
// before
MethodUtils.invokeMethod(service, "process", null);
// after
MethodUtils.invokeMethod(service, "process", new Object[]{null} /* ambiguous */);
// or better: use a typed Method reference Defensive patterns
Strategy: validation
Validate before calling
Class<?> type = target.getClass();
boolean found = false;
for (java.lang.reflect.Method m : type.getMethods())
if (m.getName().equals(methodName) && m.getParameterCount() == args.length) { found = true; break; }
if (!found) { /* method missing; fix name/arity before invoking */ } Type guard
static boolean methodExists(Class<?> c, String name, Object[] args) {
for (java.lang.reflect.Method m : c.getMethods())
if (m.getName().equals(name) && m.getParameterCount() == args.length) return true;
return false;
} Try / catch
try { MethodUtils.invokeMethod(target, name, args); }
catch (IllegalStateException e) { /* no such method; verify signature */ } Prevention
- Prefer typed calls over name-based reflection
- Pin method names to constants and unit-test them
When it happens
Trigger: Calling MethodUtils.invokeMethod(target, "doStuff", args) where the method name is wrong, the argument types do not match any overload, or the method lives on a different class/interface than target.getClass().
Common situations: Reflective helpers referencing renamed/removed methods; passing null arguments whose types cannot be inferred; invoking on a proxy/wrapper whose runtime class lacks the method; refactor that changed a method signature.
Related errors
- Can not merge result because missing method [ {merger} ] in
- Can not merge result: {e.getMessage()}
- unable to determine bean class from factory's superclass or
- create bean instance failed, type=${className}
- Expect only one but found ${size} matched constructors for t
AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14).
Data as JSON: /api/errors/85e5f20c36ba6066.
Report an issue: GitHub.