{"record":{"id":"f1ab5726c2465d80","repo":"apache/dubbo","slug":"invoke-method-argument-number-error","errorCode":null,"errorMessage":"Invoke method [{}] argument number error.","messagePattern":"Invoke method \\[(.+?)\\] argument number error\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Wrapper.java","lineNumber":101,"sourceCode":"        }\n\n        @Override\n        public Object invokeMethod(Object instance, String mn, Class<?>[] types, Object[] args)\n                throws NoSuchMethodException {\n            if (\"getClass\".equals(mn)) {\n                return instance.getClass();\n            }\n            if (\"hashCode\".equals(mn)) {\n                return instance.hashCode();\n            }\n            if (\"toString\".equals(mn)) {\n                return instance.toString();\n            }\n            if (\"equals\".equals(mn)) {\n                if (args.length == 1) {\n                    return instance.equals(args[0]);\n                }\n                throw new IllegalArgumentException(\"Invoke method [\" + mn + \"] argument number error.\");\n            }\n            throw new NoSuchMethodException(\"Method [\" + mn + \"] not found.\");\n        }\n    };\n    private static AtomicLong WRAPPER_CLASS_COUNTER = new AtomicLong(0);\n\n    /**\n     * get wrapper.\n     *\n     * @param c Class instance.\n     * @return Wrapper instance(not null).\n     */\n    public static Wrapper getWrapper(Class<?> c) {\n        return ConcurrentHashMapUtils.computeIfAbsent(WRAPPER_MAP, c, (clazz) -> {\n            while (ClassGenerator.isDynamicClass(clazz)) // can not wrapper on dynamic class.\n            {\n                clazz = clazz.getSuperclass();\n            }","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/bytecode/Wrapper.java#L83-L119","documentation":"Thrown by OBJECT_WRAPPER.invokeMethod when the method name is \"equals\" but the args array does not have exactly one element. The equals contract requires a single argument; any other arity is treated as a programming error.","triggerScenarios":"Calling wrapper.invokeMethod(instance, \"equals\", types, args) where args.length != 1 (typically 0 or 2+). Happens in generic-invocation argument wiring where equals is dispatched with the wrong argument count.","commonSituations":"A custom InvocationHandler or test harness invokes equals with zero or multiple arguments. Mismatched method metadata between provider and consumer can also produce a zero-length args array for an equals call.","solutions":["Ensure \"equals\" is always invoked with exactly one argument.","Validate args.length against the method's expected parameter count before dispatch.","If you did not intend to call equals, check for a method-name collision in your invocation metadata."],"exampleFix":"// before\nwrapper.invokeMethod(obj, \"equals\", new Class[]{}, new Object[]{});\n// after\nwrapper.invokeMethod(obj, \"equals\", new Class[]{Object.class}, new Object[]{other});","handlingStrategy":"validation","validationCode":"if (\"equals\".equals(methodName) && args != null && args.length == 1) {\n    wrapper.invokeMethod(instance, methodName, types, args);\n} else {\n    // wrong arity for equals; reject before dispatch\n}","typeGuard":"static boolean isValidEqualsCall(String mn, Object[] args) {\n    return !\"equals\".equals(mn) || (args != null && args.length == 1);\n}","tryCatchPattern":"try {\n    wrapper.invokeMethod(instance, mn, types, args);\n} catch (IllegalArgumentException e) {\n    // method arity mismatch; correct the args array\n}","preventionTips":["Always pass exactly one argument to equals.","Validate args.length against the method's expected parameter count before dispatch.","Unit-test custom InvocationHandlers with each Object method."],"tags":["reflection","bytecode","wrapper","method-invocation","argument-mismatch"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}