spring-projects/spring-framework · error · AopConfigException

Unsupported afterThrowing signature: single throwable argume

Error message

Unsupported afterThrowing signature: single throwable argument or four arguments Method, Object[], target, throwable expected: {method}

What it means

If an afterThrowing method has neither 1 nor 4 parameters, throwableParam stays null and AopConfigException is thrown. Only the single-throwable and the full 4-arg forms are recognized - zero, two, three, or five+ arg variants are unsupported.

Source

Thrown at spring-aop/src/main/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptor.java:103

					// just a Throwable parameter
					throwableParam = method.getParameterTypes()[0];
					if (!Throwable.class.isAssignableFrom(throwableParam)) {
						throw new AopConfigException("Invalid afterThrowing signature: " +
								"single argument must be a Throwable subclass");
					}
				}
				else if (method.getParameterCount() == 4) {
					// Method, Object[], target, throwable
					Class<?>[] paramTypes = method.getParameterTypes();
					if (!Method.class.equals(paramTypes[0]) || !Object[].class.equals(paramTypes[1]) ||
							Throwable.class.equals(paramTypes[2]) || !Throwable.class.isAssignableFrom(paramTypes[3])) {
						throw new AopConfigException("Invalid afterThrowing signature: " +
								"four arguments must be Method, Object[], target, throwable: " + method);
					}
					throwableParam = paramTypes[3];
				}
				if (throwableParam == null) {
					throw new AopConfigException("Unsupported afterThrowing signature: single throwable argument " +
							"or four arguments Method, Object[], target, throwable expected: " + method);
				}
				// An exception handler to register...
				Method existingMethod = this.exceptionHandlerMap.put(throwableParam, method);
				if (existingMethod != null) {
					throw new AopConfigException("Only one afterThrowing method per specific Throwable subclass " +
							"allowed: " + method + " / " + existingMethod);
				}
				if (logger.isDebugEnabled()) {
					logger.debug("Found exception handler method on throws advice: " + method);
				}
			}
		}

		if (this.exceptionHandlerMap.isEmpty()) {
			throw new AopConfigException(
					"At least one handler method must be found in class [" + throwsAdvice.getClass() + "]");
		}

View on GitHub (pinned to e8729d0438)

Solutions

  1. Reduce to either afterThrowing(ThrowableSubclass) or afterThrowing(Method, Object[], Object, ThrowableSubclass).
  2. Rename any unrelated helper methods that happen to be called 'afterThrowing'.
  3. Review all public methods named afterThrowing on the advice class.

Example fix

// before
public void afterThrowing(Method m, Object target, Exception ex) {} // 3 args

// after
public void afterThrowing(Method m, Object[] args, Object target, Exception ex) {} // 4 args
Defensive patterns

Strategy: validation

Validate before calling

for (Method m : advice.getClass().getMethods()) {
    if (m.getName().equals("afterThrowing") && m.getParameterCount() != 1 && m.getParameterCount() != 4) {
        throw new IllegalStateException("afterThrowing must have 1 or 4 args: " + m);
    }
}

Prevention

When it happens

Trigger: Defining afterThrowing() with 0 args, 2 args, 3 args, or 5+ args; an accidental helper method also named afterThrowing with a different arity.

Common situations: Refactoring that changes parameter lists; leftover debug/overloaded methods named afterThrowing; misunderstanding that only 1- and 4-arg forms are allowed.

Related errors


AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04). Data as JSON: /data/errors/f54af64e1cdca7b9.json. Report an issue: GitHub.