spring-projects/spring-framework · error · UnsupportedOperationException

Spring AOP cannot handle constructor advice

Error message

Spring AOP cannot handle constructor advice

What it means

Thrown by the AspectJAnnotationParameterNameDiscoverer when asked to resolve parameter names for a Constructor (not a Method). Spring AOP only advises methods on proxied beans; it never weaves constructor execution, so constructor advice is unsupported. This is a hard guard: any attempt to discover constructor parameter names in the AOP pipeline is rejected.

Source

Thrown at spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AbstractAspectJAdvisorFactory.java:267

				return null;
			}
			StringTokenizer nameTokens = new StringTokenizer(annotation.getArgumentNames(), ",");
			int numTokens = nameTokens.countTokens();
			if (numTokens > 0) {
				String[] names = new String[numTokens];
				for (int i = 0; i < names.length; i++) {
					names[i] = nameTokens.nextToken();
				}
				return names;
			}
			else {
				return null;
			}
		}

		@Override
		public @Nullable String @Nullable [] getParameterNames(Constructor<?> ctor) {
			throw new UnsupportedOperationException("Spring AOP cannot handle constructor advice");
		}
	}

}

View on GitHub (pinned to e8729d0438)

Solutions

  1. Do not route constructor parameter discovery through Spring AOP's AspectJAnnotationParameterNameDiscoverer; use a standard ParameterNameDiscoverer instead.
  2. If you need constructor interception, use AspectJ compile-time/load-time weaving, not Spring AOP.
Defensive patterns

Strategy: validation

Validate before calling

// Ensure you never pass a Constructor to the AOP parameter discoverer.
if (member instanceof Constructor<?> c) {
  throw new IllegalArgumentException("Constructor advice not supported; use a Method");
}

Type guard

boolean isMethodAdvice(java.lang.reflect.Member m) {
  return m instanceof java.lang.reflect.Method;
}

Prevention

When it happens

Trigger: An internal/extension code path that calls parameterNameDiscoverer.getParameterNames(Constructor) on the AspectJAnnotationParameterNameDiscoverer instance held by AbstractAspectJAdvisorFactory. Not reachable through normal @AspectJ advice processing.

Common situations: Custom subclasses or framework integrations that attempt to apply the AOP parameter discoverer to constructors. Essentially a programmer error in extending Spring AOP internals.

Related errors


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