{"record":{"id":"9b20eb9204ef02d5","repo":"apache/dubbo","slug":"not-unique-method-for-method-name-s-in-class-s","errorCode":null,"errorMessage":"Not unique method for method name(%s) in class(%s), find %d methods.","messagePattern":"Not unique method for method name\\((.+?)\\) in class\\((.+?)\\), find (.+?) methods\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/utils/ReflectUtils.java","lineNumber":914,"sourceCode":"    @Deprecated\n    public static Method findMethodByMethodSignature(Class<?> clazz, String methodName, String[] parameterTypes)\n            throws NoSuchMethodException, ClassNotFoundException {\n        Method method;\n        if (parameterTypes == null) {\n            List<Method> found = new ArrayList<>();\n            for (Method m : clazz.getMethods()) {\n                if (m.getName().equals(methodName)) {\n                    found.add(m);\n                }\n            }\n            if (found.isEmpty()) {\n                throw new NoSuchMethodException(\"No such method \" + methodName + \" in class \" + clazz);\n            }\n            if (found.size() > 1) {\n                String msg = String.format(\n                        \"Not unique method for method name(%s) in class(%s), find %d methods.\",\n                        methodName, clazz.getName(), found.size());\n                throw new IllegalStateException(msg);\n            }\n            method = found.get(0);\n        } else {\n            Class<?>[] types = new Class<?>[parameterTypes.length];\n            for (int i = 0; i < parameterTypes.length; i++) {\n                types[i] = ReflectUtils.name2class(parameterTypes[i]);\n            }\n            method = clazz.getMethod(methodName, types);\n        }\n        return method;\n    }\n\n    /**\n     * @param clazz      Target class to find method\n     * @param methodName Method signature, e.g.: method1(int, String). It is allowed to provide method name only, e.g.: method2\n     * @return target method\n     * @throws NoSuchMethodException\n     * @throws ClassNotFoundException","sourceCodeStart":896,"sourceCodeEnd":932,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ReflectUtils.java#L896-L932","documentation":"When ReflectUtils.findMethodByMethodSignature is called with parameterTypes=null (meaning 'search by name only') and more than one public method shares that name (overloads), it cannot unambiguously select one. It throws IllegalStateException with a formatted message naming the method, class, and the count of matches found. The caller must disambiguate by specifying parameter types.","triggerScenarios":"Calling ReflectUtils.findMethodByMethodSignature(clazz, methodName, null) where clazz has multiple overloaded methods with the same name — e.g. 'doSomething(String)' and 'doSomething(String, int)'. Without parameter type information, the method cannot determine which overload to return.","commonSituations":"A service interface with overloaded method names, and a generic/dynamic invocation path that looks up methods by name only. The fix is always to provide the parameter type array so the lookup is unambiguous. This can also occur in Dubbo's internal method resolution for generic invocation ($invoke) when the caller doesn't supply parameter types.","solutions":["Pass a non-null parameterTypes array to findMethodByMethodSignature to disambiguate the overload.","Alternatively, use clazz.getMethod(methodName, paramTypes...) directly for a precise lookup.","If using generic invocation ($invoke), always supply the parameter type strings alongside the arguments.","Consider renaming overloaded methods to unique names if the calling code cannot easily provide parameter types."],"exampleFix":"// before — ambiguous overload\nMethod m = ReflectUtils.findMethodByMethodSignature(\n    MyService.class, \"doSomething\", null); // 2 overloads found\n// after — specify parameter types\nMethod m = ReflectUtils.findMethodByMethodSignature(\n    MyService.class, \"doSomething\",\n    new String[]{\"java.lang.String\"});","handlingStrategy":"validation","validationCode":"// Check for overloaded methods and require parameter types if ambiguous\nlong overloadCount = Arrays.stream(clazz.getMethods())\n    .filter(m -> m.getName().equals(methodName))\n    .count();\nif (overloadCount > 1 && parameterTypes == null) {\n    throw new IllegalStateException(\n        \"Method '\" + methodName + \"' has \" + overloadCount\n        + \" overloads on \" + clazz.getName()\n        + \". Provide parameterTypes to disambiguate.\");\n}\nReflectUtils.findMethodByMethodSignature(clazz, methodName, parameterTypes);","typeGuard":null,"tryCatchPattern":"try {\n    return ReflectUtils.findMethodByMethodSignature(clazz, methodName, paramTypes);\n} catch (IllegalStateException e) {\n    if (e.getMessage().contains(\"Not unique method\")) {\n        // Disambiguate by providing parameter types from method signature\n        throw new IllegalArgumentException(\n            \"Ambiguous method. Provide parameterTypes array.\", e);\n    }\n    throw e;\n}","preventionTips":["Always pass parameter types when looking up methods that may be overloaded.","Avoid overloaded method names in Dubbo service interfaces — use distinct names instead.","In generic invocation ($invoke), always supply the parameterTypes[] argument alongside args."],"tags":["reflection","method-lookup","deprecated","method-overload","ambiguity"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}