{"id":"b9fadff730a3d9a3","repo":"spring-projects/spring-framework","slug":"is-not-an-interface","errorCode":null,"errorMessage":"[{}] is not an interface","messagePattern":"\\[(.+?)\\] is not an interface","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java","lineNumber":234,"sourceCode":"\t/**\n\t * Set the interfaces to be proxied.\n\t */\n\tpublic void setInterfaces(Class<?>... interfaces) {\n\t\tAssert.notNull(interfaces, \"Interfaces must not be null\");\n\t\tthis.interfaces.clear();\n\t\tfor (Class<?> ifc : interfaces) {\n\t\t\taddInterface(ifc);\n\t\t}\n\t}\n\n\t/**\n\t * Add a new proxied interface.\n\t * @param ifc the additional interface to proxy\n\t */\n\tpublic void addInterface(Class<?> ifc) {\n\t\tAssert.notNull(ifc, \"Interface must not be null\");\n\t\tif (!ifc.isInterface()) {\n\t\t\tthrow new IllegalArgumentException(\"[\" + ifc.getName() + \"] is not an interface\");\n\t\t}\n\t\tif (!this.interfaces.contains(ifc)) {\n\t\t\tthis.interfaces.add(ifc);\n\t\t\tadviceChanged();\n\t\t}\n\t}\n\n\t/**\n\t * Remove a proxied interface.\n\t * <p>Does nothing if the given interface isn't proxied.\n\t * @param ifc the interface to remove from the proxy\n\t * @return {@code true} if the interface was removed; {@code false}\n\t * if the interface was not found and hence could not be removed\n\t */\n\tpublic boolean removeInterface(Class<?> ifc) {\n\t\treturn this.interfaces.remove(ifc);\n\t}\n","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java#L216-L252","documentation":"Thrown by AdvisedSupport.addInterface when the supplied Class is not actually a Java interface (!ifc.isInterface()). JDK dynamic proxies can only implement interfaces, so Spring rejects any concrete class or enum passed as a proxied interface to keep the advisor model consistent. This is a hard validation enforced at configuration time.","triggerScenarios":"Calling proxyFactory.addInterface(MyConcreteClass.class) or advised.setInterfaces(SomeClass.class) where the argument is a class rather than an interface; using proxyTargetClass=false (JDK proxy mode) but adding a concrete class to the interface list; programmatic AspectJ-style wiring mistakes.","commonSituations":"Confusing the target class (which can be concrete) with proxied interfaces; accidentally passing an abstract class; generic helper code that passes arbitrary Class<?> without checking isInterface(); migrating from CGLIB to JDK proxy without converting the interface list.","solutions":["Pass only interface types to addInterface/setInterfaces; extract or identify the interface the target implements (e.g. MyService instead of MyServiceImpl).","If you really need to proxy a concrete class, enable proxyTargetClass=true (CGLIB) rather than adding the class as an interface.","Add an isInterface() guard in any generic helper that builds the interface array."],"exampleFix":"// before\nproxyFactory.setInterfaces(MyServiceImpl.class);  // concrete class\n\n// after\nproxyFactory.setInterfaces(MyService.class);  // the interface\n// or, to proxy the concrete class itself:\nproxyFactory.setProxyTargetClass(true);\nproxyFactory.setTarget(new MyServiceImpl());","handlingStrategy":"validation","validationCode":"Class<?> ifc = MyServiceImpl.class;\nif (!ifc.isInterface()) {\n  throw new IllegalArgumentException(\n    ifc.getName() + \" is not an interface; pass an interface or enable proxyTargetClass\");\n}","typeGuard":"static boolean isProxiableInterface(Class<?> c) {\n  return c != null && c.isInterface();\n}","tryCatchPattern":null,"preventionTips":["Keep a dedicated list of interface classes (never implementations) for setInterfaces.","Enable proxyTargetClass=true if you genuinely need to proxy a concrete class.","In generic helpers, assert isInterface() before addInterface."],"tags":["spring-aop","proxy","interface-validation","configuration"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}