spring-projects/spring-framework · error · IllegalStateException
MethodInvocation is not a Spring ProxyMethodInvocation: {}
Error message
MethodInvocation is not a Spring ProxyMethodInvocation: {} What it means
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.
Source
Thrown at spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAroundAdvice.java:66
@Override
public boolean isBeforeAdvice() {
return false;
}
@Override
public boolean isAfterAdvice() {
return false;
}
@Override
protected boolean supportsProceedingJoinPoint() {
return true;
}
@Override
public @Nullable Object invoke(MethodInvocation mi) throws Throwable {
if (!(mi instanceof ProxyMethodInvocation pmi)) {
throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi);
}
ProceedingJoinPoint pjp = lazyGetProceedingJoinPoint(pmi);
JoinPointMatch jpm = getJoinPointMatch(pmi);
return invokeAdviceMethod(pjp, jpm, null, null);
}
/**
* Return the ProceedingJoinPoint for the current invocation,
* instantiating it lazily if it hasn't been bound to the thread already.
* @param rmi the current Spring AOP ReflectiveMethodInvocation,
* which we'll use for attribute binding
* @return the ProceedingJoinPoint to make available to advice methods
*/
protected ProceedingJoinPoint lazyGetProceedingJoinPoint(ProxyMethodInvocation rmi) {
return new MethodInvocationProceedingJoinPoint(rmi);
}
}View on GitHub (pinned to e8729d0438)
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.
Example fix
// before advice.invoke(someCustomMethodInvocation); // not a ProxyMethodInvocation // after ProxyMethodInvocation pmi = new ReflectiveMethodInvocation(proxy, target, method, args, targetClass, chain, interceptorsAndDynamicMethodMatchers); advice.invoke(pmi);
Defensive patterns
Strategy: type-guard
Validate before calling
if (!(invocation instanceof ProxyMethodInvocation)) {
throw new IllegalArgumentException("Expecting a Spring ProxyMethodInvocation");
} Type guard
boolean isSpringInvocation = mi instanceof org.springframework.aop.ProxyMethodInvocation;
Try / catch
try {
advice.invoke(mi);
} catch (IllegalStateException ex) {
if (ex.getMessage().contains("ProxyMethodInvocation")) {
// adapt the invocation to a ProxyMethodInvocation before retrying
} else throw ex;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- MethodInvocation is not a Spring ProxyMethodInvocation: {}
- ProceedingJoinPoint is only supported for around advice
- MethodInvocation is not a Spring ProxyMethodInvocation: {}
- Expecting {} arguments to proceed, but was passed {} argumen
- 'argumentNames' property of AbstractAspectJAdvice contains a
AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04).
Data as JSON: /data/errors/2e3b3240cad8084a.json.
Report an issue: GitHub.