spring-projects/spring-framework · error · AopInvocationException
Mismatch on arguments to advice method [{}]; pointcut expres
Error message
Mismatch on arguments to advice method [{}]; pointcut expression [{}] What it means
Thrown by invokeAdviceMethodWithGivenArgs (line 650-654) when Method.invoke raises IllegalArgumentException, wrapping it as AopInvocationException. The advice method's reflective invocation could not accept the constructed argument array - a type or arity mismatch between the bound arguments and the advice method signature.
Source
Thrown at spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java:651
protected @Nullable Object invokeAdviceMethodWithGivenArgs(@Nullable Object[] args) throws Throwable {
@Nullable Object[] actualArgs = args;
if (this.aspectJAdviceMethod.getParameterCount() == 0) {
actualArgs = null;
}
Object aspectInstance = this.aspectInstanceFactory.getAspectInstance();
if (aspectInstance.equals(null)) {
// Possibly a NullBean -> simply proceed if necessary.
if (getJoinPoint() instanceof ProceedingJoinPoint pjp) {
return pjp.proceed();
}
return null;
}
try {
ReflectionUtils.makeAccessible(this.aspectJAdviceMethod);
return this.aspectJAdviceMethod.invoke(aspectInstance, actualArgs);
}
catch (IllegalArgumentException ex) {
throw new AopInvocationException("Mismatch on arguments to advice method [" +
this.aspectJAdviceMethod + "]; pointcut expression [" +
this.pointcut.getPointcutExpression() + "]", ex);
}
catch (InvocationTargetException ex) {
throw ex.getTargetException();
}
}
/**
* Overridden in around advice to return proceeding join point.
*/
protected JoinPoint getJoinPoint() {
return currentJoinPoint();
}
/**
* Get the current join point match at the join point we are being dispatched on.
*/View on GitHub (pinned to e8729d0438)
Solutions
- Align the advice parameter types with what the pointcut/returning/throwing actually supplies (widen the parameter type to match the bound value).
- For returning/throwing narrowing, ensure the bound value is assignable to the declared parameter type at every matched join point.
- Avoid primitive advice parameters where a null may be bound; use wrapper types.
- Re-check the pointcut expression quoted in the message against the advice signature.
Example fix
// before: returning narrows to Result but the pointcut may return a subtype Object
@AfterReturning(value = "execution(* svc.*(..))", returning = "ret")
public void log(Result ret) { ... }
// after
@AfterReturning(value = "execution(* svc.*(..))", returning = "ret")
public void log(Object ret) { ... } Defensive patterns
Strategy: validation
Validate before calling
// Validate that every advice parameter type is compatible with what will be bound into it.
Class<?>[] ptypes = adviceMethod.getParameterTypes();
// e.g. for returning/throwing narrowing:
if (returningName != null) {
int i = indexOf(ptypes, adviceParamNames, returningName);
if (!Object.class.isAssignableFrom(ptypes[i]) && !isAssignableFromAllMatchedReturns(pointcut, ptypes[i])) {
throw new IllegalStateException("Advice param type " + ptypes[i] + " too narrow for bound return value");
}
} Try / catch
try {
return advice.invokeAdviceMethodWithGivenArgs(args);
} catch (AopInvocationException ex) {
if (ex.getMessage().startsWith("Mismatch on arguments to advice method")) {
// inspect bound arg types vs advice parameter types and report
throw new AopInvocationException("Type/arity mismatch invoking " + adviceMethod, ex);
}
throw ex;
} Prevention
- Declare advice parameter types wide enough for every value the pointcut can bind.
- Avoid primitive advice parameters where nulls may be bound; use wrappers.
- For returning/throwing narrowing, ensure assignability at every matched join point.
- Re-check the pointcut expression (quoted in the message) against the advice signature.
When it happens
Trigger: The bound argument types do not match the advice method's declared parameter types at invocation: e.g. a pointcut binds an Object but the advice parameter is a narrower type that the value isn't assignable to; a null returned for a primitive parameter; returning/throwing values whose runtime type doesn't match the declared parameter type.
Common situations: Pointcut returning a supertype while advice declares a narrower subtype; after-throwing where the thrown exception isn't assignable to the declared exception parameter; nulls being bound into primitive parameters; mismatches between the pointcut's declared binding types and the advice signature.
Related errors
- Required to bind {} arguments, but only bound {} (JoinPointM
- 'argumentNames' property of AbstractAspectJAdvice contains a
- Returning name '{}' is neither a valid argument name nor the
- Throwing name '{}' is neither a valid argument name nor the
- Advice method [{}] requires {} arguments to be bound by name
AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04).
Data as JSON: /data/errors/a62a53792e0673d1.json.
Report an issue: GitHub.