{"record":{"id":"38407df2285df509","repo":"alibaba/arthas","slug":"iface-is-not-an-interface","errorCode":null,"errorMessage":"{iface} is not an interface","messagePattern":"(.+?) is not an interface","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"common/src/main/java/com/taobao/arthas/common/ReflectUtils.java","lineNumber":409,"sourceCode":"        for (int i = 0; i < interfaces.length; i++) {\n            addAllMethods(interfaces[i], list);\n        }\n\n        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    }","sourceCodeStart":391,"sourceCodeEnd":427,"githubUrl":"https://github.com/alibaba/arthas/blob/21cf2e9ba52b305290be7223b980ff504bb9cb5b/common/src/main/java/com/taobao/arthas/common/ReflectUtils.java#L391-L427","documentation":"Thrown by ReflectUtils.findInterfaceMethod when the Class passed in is not an interface (iface.isInterface() returns false). The utility enforces a hard precondition: it only inspects interface types via getDeclaredMethods, so concrete classes, abstract classes, arrays, and primitives are rejected up front.","triggerScenarios":"Call findInterfaceMethod(class) with a concrete class, abstract class, enum type, array type, or primitive Class object instead of a true Java interface.","commonSituations":"Accidentally passing a Class<? extends SomeImpl> where an interface type was expected; passing the implementation class of a CGLib factory rather than its interface; tooling that loads arbitrary Class objects and forwards them here.","solutions":["Pass an interface Class (e.g. Factory.class, or your annotated interface), not a class.","Guard with iface.isInterface() before calling findInterfaceMethod, and pick a different code path for non-interfaces.","Inspect the value of iface logged in the message to confirm what was actually passed."],"exampleFix":"// before\nMethod m = ReflectUtils.findInterfaceMethod(MyConcreteImpl.class);\n\n// after\nif (MyInterface.class.isInterface()) {\n    Method m = ReflectUtils.findInterfaceMethod(MyInterface.class);\n}","handlingStrategy":"type-guard","validationCode":"if (iface == null || !iface.isInterface()) {\n    // reject before calling findInterfaceMethod\n}","typeGuard":"static boolean isSingleMethodInterface(Class<?> c) {\n    return c != null && c.isInterface() && c.getDeclaredMethods().length == 1;\n}","tryCatchPattern":null,"preventionTips":["Always gate calls with iface.isInterface().","Avoid forwarding arbitrary Class objects from loaders/tooling to this utility.","Use generics (Class<? extends SomeInterface>) at API boundaries to catch misuse at compile time."],"tags":["reflection","cglib","api-contract","type-check"],"backgroundTag":null,"analyzedSha":"21cf2e9ba52b305290be7223b980ff504bb9cb5b","analyzedAt":"2026-08-14T00:57:07.243Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}