{"record":{"id":"db512d13625815bf","repo":"alibaba/arthas","slug":"expecting-exactly-1-method-in-iface","errorCode":null,"errorMessage":"expecting exactly 1 method in {iface}","messagePattern":"expecting exactly 1 method in (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"common/src/main/java/com/taobao/arthas/common/ReflectUtils.java","lineNumber":413,"sourceCode":"        return list;\n    }\n\n    public static List addAllInterfaces(Class type, List list) {\n        Class superclass = type.getSuperclass();\n        if (superclass != null) {\n            list.addAll(Arrays.asList(type.getInterfaces()));\n            addAllInterfaces(superclass, list);\n        }\n        return list;\n    }\n\n    public static Method findInterfaceMethod(Class iface) {\n        if (!iface.isInterface()) {\n            throw new IllegalArgumentException(iface + \" is not an interface\");\n        }\n        Method[] methods = iface.getDeclaredMethods();\n        if (methods.length != 1) {\n            throw new IllegalArgumentException(\"expecting exactly 1 method in \" + iface);\n        }\n        return methods[0];\n    }\n\n    // SPRING PATCH BEGIN\n    public static Class defineClass(String className, byte[] b, ClassLoader loader) throws Exception {\n        return defineClass(className, b, loader, null, null);\n    }\n\n    public static Class defineClass(String className, byte[] b, ClassLoader loader, ProtectionDomain protectionDomain)\n                    throws Exception {\n\n        return defineClass(className, b, loader, protectionDomain, null);\n    }\n\n    public static Class defineClass(String className, byte[] b, ClassLoader loader, ProtectionDomain protectionDomain,\n                    Class<?> contextClass) throws Exception {\n","sourceCodeStart":395,"sourceCodeEnd":431,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/common/src/main/java/com/taobao/arthas/common/ReflectUtils.java#L395-L431","documentation":"Thrown by ReflectUtils.findInterfaceMethod when the passed interface declares zero or more than one method (getDeclaredMethods().length != 1). The helper is built for single-method 'functional' interfaces used by CGLib; multi-method or marker interfaces are rejected because it cannot unambiguously pick the method.","triggerScenarios":"Call findInterfaceMethod(iface) where iface is a marker interface (0 methods), a multi-method interface, or an interface that inherits multiple methods whose declared set on the interface itself is not exactly 1. Note getDeclaredMethods only counts methods declared on this interface, not inherited ones.","commonSituations":"Passing a multi-method interface like Map or List; passing a marker interface like Serializable or Cloneable; passing a compound interface that combines several functional methods.","solutions":["Use a single-method (functional) interface, or split the target into one-method interfaces.","If you need a specific method on a multi-method interface, resolve it by name with Class.getMethod(name, params) instead of findInterfaceMethod.","Check getDeclaredMethods().length on the interface first to validate the precondition."],"exampleFix":"// before\nMethod m = ReflectUtils.findInterfaceMethod(MyMultiMethodApi.class);\n\n// after\nMethod m = MyMultiMethodApi.class.getMethod(\"newInstance\", argTypes);","handlingStrategy":"validation","validationCode":"if (iface == null || !iface.isInterface() || iface.getDeclaredMethods().length != 1) {\n    // not a valid single-method interface; do not call findInterfaceMethod\n}","typeGuard":"static boolean isFunctionalInterface(Class<?> c) {\n    return c != null && c.isInterface() && c.getDeclaredMethods().length == 1;\n}","tryCatchPattern":null,"preventionTips":["Prefer Java functional interfaces (single abstract method).","For multi-method interfaces, resolve the specific method by name/signature.","Validate declared-method count before delegating to findInterfaceMethod."],"tags":["reflection","cglib","api-contract"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}