{"record":{"id":"f979ee65dba2eb13","repo":"spring-projects/spring-framework","slug":"specified-class-ifc-getname-must-be-an-inter","errorCode":null,"errorMessage":"Specified class [{ifc.getName()}] must be an interface","messagePattern":"Specified class \\[(.+?)\\] must be an interface","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java","lineNumber":102,"sourceCode":"\t * Create a DefaultIntroductionAdvisor for the given advice.\n\t * @param advice the Advice to apply\n\t * @param ifc the interface to introduce\n\t */\n\tpublic DefaultIntroductionAdvisor(DynamicIntroductionAdvice advice, Class<?> ifc) {\n\t\tAssert.notNull(advice, \"Advice must not be null\");\n\t\tthis.advice = advice;\n\t\taddInterface(ifc);\n\t}\n\n\n\t/**\n\t * Add the specified interface to the list of interfaces to introduce.\n\t * @param ifc the interface to introduce\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(\"Specified class [\" + ifc.getName() + \"] must be an interface\");\n\t\t}\n\t\tthis.interfaces.add(ifc);\n\t}\n\n\t@Override\n\tpublic Class<?>[] getInterfaces() {\n\t\treturn ClassUtils.toClassArray(this.interfaces);\n\t}\n\n\t@Override\n\tpublic void validateInterfaces() throws IllegalArgumentException {\n\t\tfor (Class<?> ifc : this.interfaces) {\n\t\t\tif (this.advice instanceof DynamicIntroductionAdvice dynamicIntroductionAdvice &&\n\t\t\t\t\t!dynamicIntroductionAdvice.implementsInterface(ifc)) {\n\t\t\t\tthrow new IllegalArgumentException(\"DynamicIntroductionAdvice [\" + this.advice + \"] \" +\n\t\t\t\t\t\t\"does not implement interface [\" + ifc.getName() + \"] specified for introduction\");\n\t\t\t}\n\t\t}","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-aop/src/main/java/org/springframework/aop/support/DefaultIntroductionAdvisor.java#L84-L120","documentation":"Thrown by DefaultIntroductionAdvisor.addInterface (line 100-103) when the supplied Class is not actually an interface (ifc.isInterface() returns false). Introductions work by making the proxy implement additional interfaces, so passing a concrete class or enum type is a misuse and rejected with an IllegalArgumentException naming the offending class.","triggerScenarios":"Calling addInterface(SomeConcreteClass.class), or constructing DefaultIntroductionAdvisor with a Class argument that is a class rather than an interface. Programmatically adding an introduction with a class reference where an interface was expected.","commonSituations":"Passing an implementation class instead of its interface (e.g. FooImpl.class instead of Foo.class). Copy-paste from a place that used a class type. Generic Class<?> parameter hiding the interface requirement until runtime.","solutions":["Pass an interface type: addInterface(Foo.class) where Foo is an interface, not FooImpl.","If the type is a class, extract or define an interface it should implement and introduce that interface.","Double-check the class literal is the interface reference, not the implementation class."],"exampleFix":"// before\nadvisor.addInterface(MyServiceImpl.class); // concrete class\n\n// after\nadvisor.addInterface(MyService.class); // interface","handlingStrategy":"type-guard","validationCode":"if (!ifc.isInterface()) {\n    throw new IllegalArgumentException(ifc.getName() + \" is not an interface\");\n}\nadvisor.addInterface(ifc);","typeGuard":"static boolean isIntroductionInterface(Class<?> c) {\n    return c != null && c.isInterface();\n}","tryCatchPattern":null,"preventionTips":["Pass interface types only to DefaultIntroductionAdvisor.addInterface.","Reference the interface class literal, not the implementation class.","If only a class exists, define and introduce an interface for it."],"tags":["spring-aop","introduction","interfaces","configuration"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}