{"id":"3b50bc8f0d5ddb83","repo":"spring-projects/spring-framework","slug":"advice-object-advisor-getadvice-is-neither-a","errorCode":null,"errorMessage":"Advice object [{advisor.getAdvice()}] 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":93,"sourceCode":"\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();\n\t\tif (advice instanceof MethodInterceptor methodInterceptor) {\n\t\t\tinterceptors.add(methodInterceptor);\n\t\t}\n\t\tfor (AdvisorAdapter adapter : this.adapters) {\n\t\t\tif (adapter.supportsAdvice(advice)) {\n\t\t\t\tinterceptors.add(adapter.getInterceptor(advisor));\n\t\t\t}\n\t\t}\n\t\tif (interceptors.isEmpty()) {\n\t\t\tthrow new UnknownAdviceTypeException(advisor.getAdvice());\n\t\t}\n\t\treturn interceptors.toArray(EMPTY_METHOD_INTERCEPTOR_ARRAY);\n\t}\n\n\t@Override\n\tpublic void registerAdvisorAdapter(AdvisorAdapter adapter) {\n\t\tthis.adapters.add(adapter);\n\t}\n\n}\n","sourceCodeStart":75,"sourceCodeEnd":104,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/framework/adapter/DefaultAdvisorAdapterRegistry.java#L75-L104","documentation":"getInterceptors(Advisor) tries to produce MethodInterceptors for an Advisor's advice: directly if it is a MethodInterceptor, or via a supporting AdvisorAdapter. If neither applies, the list stays empty and UnknownAdviceTypeException is thrown, naming the advice. This is the runtime analog of error 91 - it fires at invocation-chain assembly time.","triggerScenarios":"An Advisor returns an Advice that is not a MethodInterceptor and not supported by any registered adapter, encountered when the proxy's interceptor chain is built (e.g. during getProxy() or first invocation).","commonSituations":"Custom Advice/Advisor introduced without its adapter; partial config where an adapter was registered in one registry instance but a different default registry is used at runtime; classpath changes removing the adapter bean.","solutions":["Ensure an AdvisorAdapter is registered (DefaultAdvisorAdapterRegistry.registerAdvisorAdapter) for the advice type before the proxy is built.","Make the Advisor's advice implement MethodInterceptor directly so no adapter is needed.","Use the same AdvisorAdapterRegistry instance across the ProxyFactory configuration (setAdvisorAdapterRegistry)."],"exampleFix":"// before\nclass CustomAdvisor implements Advisor {\n  public Advice getAdvice() { return new CustomAdvice(); } // unknown type\n}\n\n// after\n((DefaultAdvisorAdapterRegistry) registry).registerAdvisorAdapter(new CustomAdviceAdapter());\n// where CustomAdviceAdapter implements AdvisorAdapter and returns a MethodInterceptor","handlingStrategy":"type-guard","validationCode":"Advisor advisor = ...;\nAdvice a = advisor.getAdvice();\nboolean ok = a instanceof org.aopalliance.intercept.MethodInterceptor\n    || java.util.Arrays.stream(adapters).anyMatch(ad -> ad.supportsAdvice(a));\nif (!ok) throw new IllegalStateException(\"Advisor's advice has no adapter: \" + a.getClass());","typeGuard":"public static boolean hasInterceptorOrAdapter(Advice a, List<AdvisorAdapter> adapters) {\n    if (a instanceof org.aopalliance.intercept.MethodInterceptor) return true;\n    return adapters.stream().anyMatch(ad -> ad.supportsAdvice(a));\n}","tryCatchPattern":"try {\n    return registry.getInterceptors(advisor);\n} catch (UnknownAdviceTypeException ex) {\n    throw new BeanInitializationException(\"No adapter for advisor advice \" + advisor.getAdvice().getClass(), ex);\n}","preventionTips":["Make custom Advisor.getAdvice() return a MethodInterceptor when in doubt.","Register all custom AdvisorAdapters on the shared DefaultAdvisorAdapterRegistry.","Validate each Advisor's advice against adapters at startup, not at first invocation."],"tags":["aop","advice","interceptor","advisor-adapter"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}