{"id":"9f936b5a7c221f16","repo":"spring-projects/spring-framework","slug":"advice-object-adviceobject-is-neither-a-suppor","errorCode":null,"errorMessage":"Advice object [{adviceObject}] is neither a supported subinterface of [org.aopalliance.aop.Advice] nor an [org.springframework.aop.Advisor]","messagePattern":"Advice object \\[(.+?)\\] is neither a supported subinterface of \\[org\\.aopalliance\\.aop\\.Advice\\] nor an \\[org\\.springframework\\.aop\\.Advisor\\]","errorType":"exception","errorClass":"UnknownAdviceTypeException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/framework/adapter/DefaultAdvisorAdapterRegistry.java","lineNumber":65,"sourceCode":"\n\n\t/**\n\t * Create a new DefaultAdvisorAdapterRegistry, registering well-known adapters.\n\t */\n\tpublic DefaultAdvisorAdapterRegistry() {\n\t\tregisterAdvisorAdapter(new MethodBeforeAdviceAdapter());\n\t\tregisterAdvisorAdapter(new AfterReturningAdviceAdapter());\n\t\tregisterAdvisorAdapter(new ThrowsAdviceAdapter());\n\t}\n\n\n\t@Override\n\tpublic Advisor wrap(Object adviceObject) throws UnknownAdviceTypeException {\n\t\tif (adviceObject instanceof Advisor advisor) {\n\t\t\treturn advisor;\n\t\t}\n\t\tif (!(adviceObject instanceof Advice advice)) {\n\t\t\tthrow new UnknownAdviceTypeException(adviceObject);\n\t\t}\n\t\tif (advice instanceof MethodInterceptor) {\n\t\t\t// So well-known it doesn't even need an adapter.\n\t\t\treturn new DefaultPointcutAdvisor(advice);\n\t\t}\n\t\tfor (AdvisorAdapter adapter : this.adapters) {\n\t\t\t// Check that it is supported.\n\t\t\tif (adapter.supportsAdvice(advice)) {\n\t\t\t\treturn new DefaultPointcutAdvisor(advice);\n\t\t\t}\n\t\t}\n\t\tthrow new UnknownAdviceTypeException(advice);\n\t}\n\n\t@Override\n\tpublic MethodInterceptor[] getInterceptors(Advisor advisor) throws UnknownAdviceTypeException {\n\t\tList<MethodInterceptor> interceptors = new ArrayList<>(3);\n\t\tAdvice advice = advisor.getAdvice();","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/framework/adapter/DefaultAdvisorAdapterRegistry.java#L47-L83","documentation":"DefaultAdvisorAdapterRegistry.wrap() throws UnknownAdviceTypeException when the object passed is not an Advisor and not even an instance of org.aopalliance.aop.Advice. The adapters (MethodBefore/AfterReturning/Throws) only know how to wrap actual Advice subinterfaces, so a plain object is rejected at this first type check.","triggerScenarios":"Passing a raw POJO (no Advice/Advisor interface) to wrap(); calling addAdvice() / addAdvisor() on an Advised with an unsupported object; misconfigured interceptor that is the wrong type.","commonSituations":"Registering a plain bean as advice instead of a MethodBeforeAdvice/MethodInterceptor/etc.; copy-paste wiring pointing at the wrong bean; classpath has an older advice class missing the interface.","solutions":["Make the advice class implement MethodInterceptor, MethodBeforeAdvice, AfterReturningAdvice, ThrowsAdvice, or Advisor.","Verify the bean you pass to wrap()/addAdvice() is actually typed as Advice in your configuration.","If wrapping a third-party interceptor, adapt it with a custom AdvisorAdapter."],"exampleFix":"// before\nclass MyLogger { void log() {} } // not an Advice\nfactory.addAdvice(new MyLogger());\n\n// after\nclass MyLogger implements MethodBeforeAdvice {\n  public void before(Method m, Object[] args, Object target) { log(); }\n}\nfactory.addAdvice(new MyLogger());","handlingStrategy":"type-guard","validationCode":"public void safeAddAdvice(Advised advised, Object candidate) {\n    if (!(candidate instanceof org.aopalliance.aop.Advice)\n            && !(candidate instanceof org.springframework.aop.Advisor)) {\n        throw new IllegalArgumentException(\"Not Advice/Advisor: \" + candidate);\n    }\n    advised.addAdvice((org.aopalliance.aop.Advice) candidate);\n}","typeGuard":"public static boolean isAdviceOrAdvisor(Object o) {\n    return o instanceof org.aopalliance.aop.Advice || o instanceof org.springframework.aop.Advisor;\n}","tryCatchPattern":"try {\n    registry.wrap(candidate);\n} catch (UnknownAdviceTypeException ex) {\n    throw new IllegalArgumentException(candidate + \" must implement Advice or Advisor\", ex);\n}","preventionTips":["Implement MethodInterceptor/MethodBeforeAdvice/AfterReturningAdvice/ThrowsAdvice or Advisor on advice classes.","Type-check the object with instanceof before passing to wrap/addAdvice.","Wire advice beans by type, not by name, to catch mismatches at injection time."],"tags":["aop","advice","advisor","type-mismatch"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}