spring-projects/spring-framework · error · IllegalStateException
Not enough arguments in method to satisfy binding of returni
Error message
Not enough arguments in method to satisfy binding of returning and throwing variables
What it means
Thrown by AspectJAdviceParameterNameDiscoverer.getParameterNames (line 233-236) when the number of advice method parameters is less than the minimum required to hold both the returning and throwing bindings (one slot each). The discoverer computes minimumNumberUnboundArgs from returningName/throwingName and rejects if the method cannot even accommodate them.
Source
Thrown at spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAdviceParameterNameDiscoverer.java:234
* for this class for details on the algorithm used.
* @param method the target {@link Method}
* @return the parameter names
*/
@Override
public @Nullable String @Nullable [] getParameterNames(Method method) {
this.argumentTypes = method.getParameterTypes();
this.numberOfRemainingUnboundArguments = this.argumentTypes.length;
this.parameterNameBindings = new String[this.numberOfRemainingUnboundArguments];
int minimumNumberUnboundArgs = 0;
if (this.returningName != null) {
minimumNumberUnboundArgs++;
}
if (this.throwingName != null) {
minimumNumberUnboundArgs++;
}
if (this.numberOfRemainingUnboundArguments < minimumNumberUnboundArgs) {
throw new IllegalStateException(
"Not enough arguments in method to satisfy binding of returning and throwing variables");
}
try {
int algorithmicStep = STEP_JOIN_POINT_BINDING;
while (this.numberOfRemainingUnboundArguments > 0 && algorithmicStep < STEP_FINISHED) {
switch (algorithmicStep++) {
case STEP_JOIN_POINT_BINDING -> {
if (!maybeBindThisJoinPoint()) {
maybeBindThisJoinPointStaticPart();
}
}
case STEP_THROWING_BINDING -> maybeBindThrowingVariable();
case STEP_ANNOTATION_BINDING -> maybeBindAnnotationsFromPointcutExpression();
case STEP_RETURNING_BINDING -> maybeBindReturningVariable();
case STEP_PRIMITIVE_ARGS_BINDING -> maybeBindPrimitiveArgsFromPointcutExpression();
case STEP_THIS_TARGET_ARGS_BINDING -> maybeBindThisOrTargetOrArgsFromPointcutExpression();
case STEP_REFERENCE_PCUT_BINDING -> maybeBindReferencePointcutParameter();View on GitHub (pinned to e8729d0438)
Solutions
- Add enough parameters to the advice method to hold each returning/throwing binding (plus any join-point param).
- Remove the returning and/or throwing attribute if the method does not need to bind those values.
- Split a single method trying to bind both return and exception into separate after-returning and after-throwing advice methods.
Example fix
// before
@AfterReturning(value = "...", returning = "ret", throwing = "ex")
public void log(JoinPoint jp) { ... } // only 1 param, needs 3
// after
@AfterReturning(value = "...", returning = "ret")
public void onRet(JoinPoint jp, Object ret) { ... }
@AfterThrowing(value = "...", throwing = "ex")
public void onThrow(JoinPoint jp, Throwable ex) { ... } Defensive patterns
Strategy: validation
Validate before calling
// Before wiring, verify the advice method can hold returning+throwing bindings.
int needed = (returningName != null ? 1 : 0) + (throwingName != null ? 1 : 0);
if (adviceMethod.getParameterCount() < needed) {
throw new IllegalStateException("Advice " + adviceMethod + " has only "
+ adviceMethod.getParameterCount() + " params but " + needed + " returning/throwing bindings set");
} Prevention
- Ensure the advice method declares a parameter for each returning/throwing binding plus any join-point param.
- Do not combine returning and throwing on a single advice method; split into after-returning and after-throwing.
- Re-count parameters after removing a returning/throwing parameter.
When it happens
Trigger: Configuring after-returning/after-throwing binding (or both) on an advice method with too few parameters: e.g. returning='ret' and throwing='ex' both set but the method has only one parameter, or a method with zero parameters and returning set.
Common situations: Setting both returning and throwing on a method that has only a join-point parameter; removing a parameter from the advice method but leaving returning/throwing attributes; misconfigured XML combining after-returning and after-throwing semantics on one method.
Related errors
- Expecting to find {} arguments to bind by name in advice, bu
- 'argumentNames' property of AbstractAspectJAdvice contains a
- Advice method [{}] requires {} arguments to be bound by name
- Returning argument name '{}' was not bound in advice argumen
- Throwing argument name '{}' was not bound in advice argument
AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04).
Data as JSON: /data/errors/1fb53de1fb32a46a.json.
Report an issue: GitHub.