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
- Do not route constructor parameter discovery through Spring AOP's AspectJAnnotationParameterNameDiscoverer; use a standard ParameterNameDiscoverer instead.
- 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
- Do not extend AbstractAspectJAdvisorFactory's parameter discoverer for constructor use.
- Use AspectJ weaving for constructor interception.
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
- MethodInvocation is not a Spring ProxyMethodInvocation: {}
- 'argumentNames' property of AbstractAspectJAdvice contains a
- Only afterReturning advice can be used to bind a return valu
- Returning name '{}' is neither a valid argument name nor the
- Only afterThrowing advice can be used to bind a thrown excep
AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04).
Data as JSON: /data/errors/8bbf33fbc91329be.json.
Report an issue: GitHub.