spring-projects/spring-framework · error · AopConfigException

Unsupported afterThrowing signature: single throwable…

Error message

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

What it means

Thrown as AopConfigException by ThrowsAdviceInterceptor's constructor when an afterThrowing method has a parameter count that is neither 1 nor 4. After scanning, throwableParam is still null (line 102), so the signature is unsupported. The ThrowsAdvice contract only allows the one-arg (Throwable) or four-arg (Method, Object[], target, Throwable) forms.

Solutions

  1. Reduce to the supported arity: one Throwable parameter, or four (Method, Object[], Object, Throwable).
  2. Rename unrelated helper methods so they are not called 'afterThrowing'.

Example fix

// before
public void afterThrowing(Method m, Object[] args, Object target, Exception ex, Map ctx) { ... } // 5 params

// after
public void afterThrowing(Method m, Object[] args, Object target, Exception ex) { ... }
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("Unsupported afterThrowing arity: " + m);
  }
}

Type guard

static boolean supportedThrowsArity(Method m) {
  return m.getName().equals("afterThrowing") && (m.getParameterCount() == 1 || m.getParameterCount() == 4);
}

Try / catch

try { new ThrowsAdviceInterceptor(advice); }
catch (AopConfigException e) {
  if (e.getMessage().contains("Unsupported afterThrowing signature")) { /* fix arity to 1 or 4 */ }
  throw e;
}

Prevention

When it happens

Trigger: A method named 'afterThrowing' with 0, 2, 3, or 5+ parameters on a ThrowsAdvice implementation. The constructor finds the method by name and then fails the arity check.

Common situations: Overloading afterThrowing with extra context parameters; partial implementations; typos that add or drop parameters.

Related errors


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

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