{"record":{"id":"2e3b3240cad8084a","repo":"spring-projects/spring-framework","slug":"methodinvocation-is-not-a-spring-proxymethodinvoca-2e3b32","errorCode":null,"errorMessage":"MethodInvocation is not a Spring ProxyMethodInvocation: {}","messagePattern":"MethodInvocation is not a Spring ProxyMethodInvocation: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAroundAdvice.java","lineNumber":66,"sourceCode":"\t@Override\n\tpublic boolean isBeforeAdvice() {\n\t\treturn false;\n\t}\n\n\t@Override\n\tpublic boolean isAfterAdvice() {\n\t\treturn false;\n\t}\n\n\t@Override\n\tprotected boolean supportsProceedingJoinPoint() {\n\t\treturn true;\n\t}\n\n\t@Override\n\tpublic @Nullable Object invoke(MethodInvocation mi) throws Throwable {\n\t\tif (!(mi instanceof ProxyMethodInvocation pmi)) {\n\t\t\tthrow new IllegalStateException(\"MethodInvocation is not a Spring ProxyMethodInvocation: \" + mi);\n\t\t}\n\t\tProceedingJoinPoint pjp = lazyGetProceedingJoinPoint(pmi);\n\t\tJoinPointMatch jpm = getJoinPointMatch(pmi);\n\t\treturn invokeAdviceMethod(pjp, jpm, null, null);\n\t}\n\n\t/**\n\t * Return the ProceedingJoinPoint for the current invocation,\n\t * instantiating it lazily if it hasn't been bound to the thread already.\n\t * @param rmi the current Spring AOP ReflectiveMethodInvocation,\n\t * which we'll use for attribute binding\n\t * @return the ProceedingJoinPoint to make available to advice methods\n\t */\n\tprotected ProceedingJoinPoint lazyGetProceedingJoinPoint(ProxyMethodInvocation rmi) {\n\t\treturn new MethodInvocationProceedingJoinPoint(rmi);\n\t}\n\n}","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAroundAdvice.java#L48-L84","documentation":"Thrown by AspectJAroundAdvice.invoke() when the received MethodInvocation is not a Spring ProxyMethodInvocation. Spring's @Around advice needs ProxyMethodInvocation to expose the proxy object and to clone the invocation for proceed() calls. This indicates the advice was invoked outside Spring's normal proxy infrastructure or with a non-Spring interceptor chain.","triggerScenarios":"Manually invoking AspectJAroundAdvice.invoke() with a plain AOP Alliance MethodInvocation that does not implement ProxyMethodInvocation, or plugging Spring around-advice into a non-Spring interceptor framework.","commonSituations":"Custom interceptor frameworks, unit tests that mock MethodInvocation without using ReflectiveMethodInvocation, or integration with other AOP Alliance-based libraries that provide their own MethodInvocation implementations.","solutions":["Use Spring's ReflectiveMethodInvocation or CglibMethodInvocation when manually invoking advice","Let Spring's ProxyFactory / proxy infrastructure invoke the advice — do not call invoke() manually","If you must adapt a foreign chain, wrap the MethodInvocation in a class that implements ProxyMethodInvocation"],"exampleFix":"// before\nAspectJAroundAdvice advice = ...;\nMethodInvocation foreignMi = new MyCustomMethodInvocation(...);\nadvice.invoke(foreignMi); // throws: not a ProxyMethodInvocation\n\n// after\nProxyMethodInvocation springMi = new ReflectiveMethodInvocation(proxy, target, method, args, targetClass, chain, ...);\nadvice.invoke(springMi);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Type guard: verify the MethodInvocation is a Spring ProxyMethodInvocation before invoking\nimport org.springframework.aop.ProxyMethodInvocation;\n\nif (mi instanceof ProxyMethodInvocation pmi) {\n    advice.invoke(pmi);\n} else {\n    throw new IllegalArgumentException(\n        \"Cannot invoke AspectJAroundAdvice with non-Spring MethodInvocation: \" + mi.getClass());\n}","tryCatchPattern":"try {\n    advice.invoke(mi);\n} catch (IllegalStateException ex) {\n    if (ex.getMessage().contains(\"ProxyMethodInvocation\")) {\n        // Replace with a Spring ReflectiveMethodInvocation or avoid manual invocation\n    }\n    throw ex;\n}","preventionTips":["Never manually invoke AspectJAroundAdvice — let Spring's ProxyFactory create the proxy and dispatch invocations","If you must build a MethodInvocation manually, use Spring's ReflectiveMethodInvocation which implements ProxyMethodInvocation"],"tags":["spring-aop","aspectj","around-advice","proxy"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}