{"id":"08cac5ec7ec038f7","repo":"spring-projects/spring-framework","slug":"cannot-invoke-methods-message","errorCode":null,"errorMessage":"Cannot invoke methods: {message}","messagePattern":"Cannot invoke methods: (.+?)","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java","lineNumber":613,"sourceCode":"\t */\n\tprivate static class PrototypePlaceholderAdvisor implements Advisor, Serializable {\n\n\t\tprivate final String beanName;\n\n\t\tprivate final String message;\n\n\t\tpublic PrototypePlaceholderAdvisor(String beanName) {\n\t\t\tthis.beanName = beanName;\n\t\t\tthis.message = \"Placeholder for prototype Advisor/Advice with bean name '\" + beanName + \"'\";\n\t\t}\n\n\t\tpublic String getBeanName() {\n\t\t\treturn this.beanName;\n\t\t}\n\n\t\t@Override\n\t\tpublic Advice getAdvice() {\n\t\t\tthrow new UnsupportedOperationException(\"Cannot invoke methods: \" + this.message);\n\t\t}\n\n\t\t@Override\n\t\tpublic String toString() {\n\t\t\treturn this.message;\n\t\t}\n\t}\n\n}\n","sourceCodeStart":595,"sourceCodeEnd":623,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java#L595-L623","documentation":"PrototypePlaceholderAdvisor.getAdvice() is not supported - the placeholder is only an internal marker holding a bean name until the real prototype advisor can be resolved. Calling getAdvice() (or any reflective invocation that needs the advice) triggers UnsupportedOperationException with this message.","triggerScenarios":"Reflectively inspecting or invoking a PrototypePlaceholderAdvisor's advice before the placeholder has been replaced during freshAdvisorChain(); programmatically calling getAdvice() on advisors obtained from a prototype-mode ProxyFactoryBean that has not yet materialized its chain.","commonSituations":"Custom introspection code that iterates getAdvisors() and calls getAdvice() on each; tooling/debuggers touching the placeholder; AOP infrastructure code that does not first refresh the prototype chain.","solutions":["Do not call getAdvice() on advisors of a prototype ProxyFactoryBean; trigger proxy creation first so placeholders are resolved into real advisors.","Filter out PrototypePlaceholderAdvisor instances (they are private, so check via instanceof Advisor and getClass().getName()) before introspection.","Switch the advice bean to singleton scope to eliminate placeholders."],"exampleFix":"// before\nfor (Advisor a : proxyFactoryBean.getAdvisors()) {\n  a.getAdvice(); // blows up on placeholder\n}\n\n// after\n// trigger materialization first, then introspect\nObject proxy = proxyFactoryBean.getObject();\nAdvised advised = (Advised) proxy;\nfor (Advisor a : advised.getAdvisors()) {\n  a.getAdvice(); // safe - resolved\n}","handlingStrategy":"type-guard","validationCode":"// Avoid calling getAdvice() on unmaterialized placeholders\nfor (Advisor a : advised.getAdvisors()) {\n    if (!a.getClass().getName().contains(\"PrototypePlaceholderAdvisor\")) {\n        a.getAdvice();\n    }\n}","typeGuard":"public static boolean isResolvedAdvisor(Advisor a) {\n    return a != null && !a.getClass().getName().contains(\"PrototypePlaceholderAdvisor\");\n}","tryCatchPattern":"try {\n    return advisor.getAdvice();\n} catch (UnsupportedOperationException ex) {\n    if (ex.getMessage().startsWith(\"Cannot invoke methods\")) {\n        log.warn(\"Skipping placeholder advisor: {}\", advisor);\n        return null;\n    }\n    throw ex;\n}","preventionTips":["Trigger proxy creation (getObject()) before introspecting advisors so placeholders are resolved.","Filter PrototypePlaceholderAdvisor instances out of introspection loops.","Switch prototype advice to singleton scope when introspection is required."],"tags":["aop","prototype","advisor","unsupported-operation"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}