spring-projects/spring-framework · error · IllegalArgumentException

Expecting arguments to proceed, but was passed arguments

Error message

Expecting {} arguments to proceed, but was passed {} arguments

What it means

Thrown by MethodInvocationProceedingJoinPoint.proceed(Object[]) when the supplied argument array length does not match the intercepted method's argument count. Spring replaces the invocation arguments in-place, so the new array must have exactly the same number of elements as the current getArguments().

Solutions

  1. Pass pjp.getArgs() unchanged if you are not modifying arguments, using the no-arg proceed() variant
  2. Build the new array with the same length as pjp.getArgs() and copy/modify individual elements
  3. Validate arguments.length == joinPoint.getArgs().length before calling proceed(arguments)

Example fix

// before
@Around("execution(* com.example..*(..))")
public Object around(ProceedingJoinPoint pjp) throws Throwable {
    return pjp.proceed(new Object[]{modifiedArg}); // wrong count
}

// after
@Around("execution(* com.example..*(..))")
public Object around(ProceedingJoinPoint pjp) throws Throwable {
    Object[] args = pjp.getArgs();
    args[0] = modifiedArg;
    return pjp.proceed(args);
}
Defensive patterns

Strategy: validation

Validate before calling

// Validate argument count before calling proceed(Object[])
Object[] args = pjp.getArgs();
if (modifiedArgs.length != args.length) {
    throw new IllegalArgumentException(
        "Expected " + args.length + " args but got " + modifiedArgs.length);
}
pjp.proceed(modifiedArgs);

Prevention

When it happens

Trigger: In an @Around advice, calling pjp.proceed(new Object[]{arg1}) when the target method takes 3 parameters, or calling pjp.proceed(new Object[0]) on a method that takes 2 params.

Common situations: Advice that tries to modify or suppress specific arguments and passes the wrong total count, or that builds a partial array from getArgs() without copying all elements.

Related errors


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

Appendix: source

Thrown at spring-aop/src/main/java/org/springframework/aop/aspectj/MethodInvocationProceedingJoinPoint.java:89

		this.methodInvocation = methodInvocation;
	}


	@Override
	public void set$AroundClosure(AroundClosure aroundClosure) {
		throw new UnsupportedOperationException();
	}

	@Override
	public @Nullable Object proceed() throws Throwable {
		return this.methodInvocation.invocableClone().proceed();
	}

	@Override
	public @Nullable Object proceed(Object[] arguments) throws Throwable {
		Assert.notNull(arguments, "Argument array passed to proceed cannot be null");
		if (arguments.length != this.methodInvocation.getArguments().length) {
			throw new IllegalArgumentException("Expecting " +
					this.methodInvocation.getArguments().length + " arguments to proceed, " +
					"but was passed " + arguments.length + " arguments");
		}
		this.methodInvocation.setArguments(arguments);
		return this.methodInvocation.invocableClone(arguments).proceed();
	}

	/**
	 * Returns the Spring AOP proxy. Cannot be {@code null}.
	 */
	@Override
	public Object getThis() {
		return this.methodInvocation.getProxy();
	}

	/**
	 * Returns the Spring AOP target. May be {@code null} if there is no target.
	 */

View on GitHub (pinned to 69bf83ad71)