{"record":{"id":"8cd849dcfb141455","repo":"apache/dubbo","slug":"no-method-found-with-the-specified-name-and-parame","errorCode":null,"errorMessage":"No method found with the specified name and parameter types","messagePattern":"No method found with the specified name and parameter types","errorType":"exception","errorClass":"NoSuchMethodException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/utils/ReflectionUtils.java","lineNumber":76,"sourceCode":"     *\n     * @param source     The object on which to invoke the method.\n     * @param methodName The name of the method to invoke.\n     * @param params     The parameters to pass to the method.\n     * @return The result of invoking the specified method on the given object.\n     */\n    public static Object invoke(Object source, String methodName, Object... params) {\n        try {\n            Class<?>[] classes = Arrays.stream(params)\n                    .map(param -> param != null ? param.getClass() : null)\n                    .toArray(Class<?>[]::new);\n\n            for (Method method : source.getClass().getDeclaredMethods()) {\n                if (method.getName().equals(methodName) && matchParameters(method.getParameterTypes(), classes)) {\n                    method.setAccessible(true);\n                    return method.invoke(source, params);\n                }\n            }\n            throw new NoSuchMethodException(\"No method found with the specified name and parameter types\");\n        } catch (Exception e) {\n            throw new ReflectionException(e);\n        }\n    }\n\n    private static boolean matchParameters(Class<?>[] methodParamTypes, Class<?>[] givenParamTypes) {\n        if (methodParamTypes.length != givenParamTypes.length) {\n            return false;\n        }\n\n        for (int i = 0; i < methodParamTypes.length; i++) {\n            if (givenParamTypes[i] == null) {\n                if (methodParamTypes[i].isPrimitive()) {\n                    return false;\n                }\n            } else if (!methodParamTypes[i].isAssignableFrom(givenParamTypes[i])) {\n                return false;\n            }","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ReflectionUtils.java#L58-L94","documentation":"Thrown by ReflectionUtils.invoke(Object, String, Object...) when no method on the source class matches both the given name and the runtime parameter types. The NoSuchMethodException is then wrapped in ReflectionException. Matching uses getDeclaredMethods (not inherited) and compares param types via isAssignableFrom, so overloaded methods and superclass methods are easily missed.","triggerScenarios":"Calling invoke(obj, \"doSomething\", args) where no declared method has that exact name with parameter types assignable from the runtime types of args; method exists on a superclass (not declared on obj.getClass()); passing boxed types (Integer) for a method expecting primitives.","commonSituations":"Testing a method that was renamed or overloaded; invoking a method defined in a parent class via a subclass instance; mismatch between autoboxed argument types and primitive parameter types in matchParameters.","solutions":["Verify the method name and parameter signature exist as a declared method on source.getClass() (not just a superclass).","Ensure argument types are assignable to the method's parameter types; check for primitive vs. boxed-type mismatches.","Catch ReflectionException and inspect getCause() to confirm it is NoSuchMethodException."],"exampleFix":"// before\nReflectionUtils.invoke(obj, \"process\", 42);\n// fails if process(long) is on a superclass\n\n// after\n// ensure method is declared on the concrete class, or call directly\nobj.process(42);","handlingStrategy":"try-catch","validationCode":"boolean methodExists = Arrays.stream(source.getClass().getDeclaredMethods())\n    .anyMatch(m -> m.getName().equals(methodName));\nif (!methodExists) throw new AssertionError(\"method not found: \" + methodName);","typeGuard":null,"tryCatchPattern":"try {\n    Object result = ReflectionUtils.invoke(source, methodName, params);\n} catch (ReflectionUtils.ReflectionException e) {\n    if (e.getCause() instanceof NoSuchMethodException) {\n        // no matching method — handle gracefully\n    }\n}","preventionTips":["Remember invoke only scans getDeclaredMethods on the exact class — inherited methods are not found.","Watch for primitive vs. boxed-type mismatches in parameter matching."],"tags":["reflection","method-invocation","testing","dubbo-common"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}