{"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/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAroundAdvice.java#L48-L84","documentation":"Thrown by AspectJAroundAdvice.invoke when the MethodInvocation passed to an @Around advice is not an instance of Spring's ProxyMethodInvocation. Spring's around-advice machinery (ProceedingJoinPoint, argument cloning, proxy exposure) depends on ProxyMethodInvocation-specific APIs, so a foreign or custom MethodInvocation implementation cannot be handled.","triggerScenarios":"Invoking an AspectJAroundAdvice directly with a non-Spring MethodInvocation; integrating a third-party AOP framework that produces its own MethodInvocation; manually constructing and calling an advice chain with a custom invocation object.","commonSituations":"Custom interceptors that wrap or replace Spring's ReflectiveMethodInvocation; unit tests that pass a mock MethodInvocation to an around advice; mixing Spring AOP with another AOP stack.","solutions":["Ensure the advice is only invoked through Spring's proxy infrastructure (ProxyFactory, AopProxy), which always supplies a ProxyMethodInvocation.","If invoking advice programmatically, pass a ReflectiveMethodInvocation or subclass of ProxyMethodInvocation.","Do not route non-Spring MethodInvocation objects through Spring @Around advice; adapt them first."],"exampleFix":"// before\nadvice.invoke(someCustomMethodInvocation); // not a ProxyMethodInvocation\n\n// after\nProxyMethodInvocation pmi = new ReflectiveMethodInvocation(proxy, target, method, args, targetClass, chain, interceptorsAndDynamicMethodMatchers);\nadvice.invoke(pmi);","handlingStrategy":"type-guard","validationCode":"if (!(invocation instanceof ProxyMethodInvocation)) {\n    throw new IllegalArgumentException(\"Expecting a Spring ProxyMethodInvocation\");\n}","typeGuard":"boolean isSpringInvocation = mi instanceof org.springframework.aop.ProxyMethodInvocation;","tryCatchPattern":"try {\n    advice.invoke(mi);\n} catch (IllegalStateException ex) {\n    if (ex.getMessage().contains(\"ProxyMethodInvocation\")) {\n        // adapt the invocation to a ProxyMethodInvocation before retrying\n    } else throw ex;\n}","preventionTips":["Always build proxies via Spring's ProxyFactory / AopProxy so invocations are ProxyMethodInvocation.","Do not feed third-party MethodInvocation objects into Spring @Around advice.","In tests, use ReflectiveMethodInvocation or mock ProxyMethodInvocation."],"tags":["spring-aop","aspectj","proxy","around-advice"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}