{"record":{"id":"85e5f20c36ba6066","repo":"apache/dubbo","slug":"cannot-find-method-s-class-s","errorCode":null,"errorMessage":"cannot find method %s,class: %s","messagePattern":"cannot find method (.+?),class: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/utils/MethodUtils.java","lineNumber":288,"sourceCode":"\n    /**\n     * Invoke the target object and method\n     *\n     * @param object           the target object\n     * @param methodName       the method name\n     * @param methodParameters the method parameters\n     * @param <T>              the return type\n     * @return the target method's execution result\n     * @since 2.7.6\n     */\n    static <T> T invokeMethod(Object object, String methodName, Object... methodParameters) {\n        Class type = object.getClass();\n        Class[] parameterTypes = resolveTypes(methodParameters);\n        Method method = findMethod(type, methodName, parameterTypes);\n        T value = null;\n\n        if (method == null) {\n            throw new IllegalStateException(\n                    String.format(\"cannot find method %s,class: %s\", methodName, type.getName()));\n        }\n\n        try {\n            final boolean isAccessible = method.isAccessible();\n\n            if (!isAccessible) {\n                method.setAccessible(true);\n            }\n            value = (T) method.invoke(object, methodParameters);\n            method.setAccessible(isAccessible);\n        } catch (Exception e) {\n            throw new IllegalArgumentException(e);\n        }\n\n        return value;\n    }\n","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/MethodUtils.java#L270-L306","documentation":"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.","triggerScenarios":"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().","commonSituations":"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.","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"],"exampleFix":"// before\nMethodUtils.invokeMethod(service, \"process\", null);\n// after\nMethodUtils.invokeMethod(service, \"process\", new Object[]{null} /* ambiguous */);\n// or better: use a typed Method reference","handlingStrategy":"validation","validationCode":"Class<?> type = target.getClass();\nboolean found = false;\nfor (java.lang.reflect.Method m : type.getMethods())\n    if (m.getName().equals(methodName) && m.getParameterCount() == args.length) { found = true; break; }\nif (!found) { /* method missing; fix name/arity before invoking */ }","typeGuard":"static boolean methodExists(Class<?> c, String name, Object[] args) {\n    for (java.lang.reflect.Method m : c.getMethods())\n        if (m.getName().equals(name) && m.getParameterCount() == args.length) return true;\n    return false;\n}","tryCatchPattern":"try { MethodUtils.invokeMethod(target, name, args); }\ncatch (IllegalStateException e) { /* no such method; verify signature */ }","preventionTips":["Prefer typed calls over name-based reflection","Pin method names to constants and unit-test them"],"tags":["reflection","method","invocation"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}