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 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.

Solutions

  1. Use Spring's ReflectiveMethodInvocation or CglibMethodInvocation when manually invoking advice
  2. Let Spring's ProxyFactory / proxy infrastructure invoke the advice — do not call invoke() manually
  3. If you must adapt a foreign chain, wrap the MethodInvocation in a class that implements ProxyMethodInvocation

Example fix

// before
AspectJAroundAdvice advice = ...;
MethodInvocation foreignMi = new MyCustomMethodInvocation(...);
advice.invoke(foreignMi); // throws: not a ProxyMethodInvocation

// after
ProxyMethodInvocation springMi = new ReflectiveMethodInvocation(proxy, target, method, args, targetClass, chain, ...);
advice.invoke(springMi);
Defensive patterns

Strategy: type-guard

Type guard

// Type guard: verify the MethodInvocation is a Spring ProxyMethodInvocation before invoking
import org.springframework.aop.ProxyMethodInvocation;

if (mi instanceof ProxyMethodInvocation pmi) {
    advice.invoke(pmi);
} else {
    throw new IllegalArgumentException(
        "Cannot invoke AspectJAroundAdvice with non-Spring MethodInvocation: " + mi.getClass());
}

Try / catch

try {
    advice.invoke(mi);
} catch (IllegalStateException ex) {
    if (ex.getMessage().contains("ProxyMethodInvocation")) {
        // Replace with a Spring ReflectiveMethodInvocation or avoid manual invocation
    }
    throw ex;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09). Data as JSON: /api/errors/2e3b3240cad8084a. Report an issue: GitHub.

Appendix: 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 69bf83ad71)