spring-projects/spring-framework · error · UnsupportedOperationException
Spring AOP cannot handle constructor advice
Error message
Spring AOP cannot handle constructor advice
What it means
Thrown as an UnsupportedOperationException from AspectJAnnotationParameterNameDiscoverer.getParameterNames(Constructor). Spring AOP only supports method-level advice (@Before, @After, @Around, etc.); AspectJ also allows constructor execution/initialization advice, but Spring's proxy-based AOP cannot intercept constructors. This is triggered if the parameter-name discovery path is exercised for a constructor, which does not occur during normal Spring AOP processing.
Solutions
- Do not attempt constructor-level advice through Spring AOP; use method-level advice instead.
- Avoid calling getParameterNames(Constructor) on the AspectJ annotation parameter discoverer; use a different discoverer for constructors.
- If constructor interception is required, use AspectJ compile-time or load-time weaving.
Defensive patterns
Strategy: validation
Validate before calling
// Spring AOP never invokes constructor parameter discovery through this path in normal use. // Defense: do not call AspectJAnnotationParameterNameDiscoverer.getParameterNames(Constructor). // Use a different ParameterNameDiscoverer (e.g., DefaultParameterNameDiscoverer) for constructors.
Try / catch
// Not applicable in user code; if extending the framework, guard before calling:
ParameterNameDiscoverer discoverer = ...;
if (executable instanceof Method mth) {
return discoverer.getParameterNames(mth); // safe for AspectJ discoverer
} else {
return otherDiscoverer.getParameterNames((Constructor<?>) executable);
} Prevention
- Do not attempt constructor advice in Spring AOP; it is unsupported by design.
- Use AspectJ weaving if constructor interception is required.
- Avoid reusing the AspectJ annotation parameter discoverer for constructor analysis.
When it happens
Trigger: A custom ParameterNameDiscoverer wiring that calls getParameterNames(Constructor) on the AspectJAnnotationParameterNameDiscoverer; framework/test code invoking parameter discovery on a constructor of an advice type; programmatic misuse of the internal discoverer.
Common situations: Tooling or extensions that reuse Spring's ParameterNameDiscoverer infrastructure on constructors; misconfiguration where a generic discoverer chain is applied to constructors; user attempting to define constructor advice via Spring AOP (not supported).
Related errors
- Advice method [ ] requires arguments to be bound by name…
- Advice must be declared inside an aspect type: Offending…
- An advice method can never be a constructor
- is not a valid AspectJ annotation
- 'argumentNames' property of AbstractAspectJAdvice contains…
AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09).
Data as JSON: /api/errors/8bbf33fbc91329be.
Report an issue: GitHub.
Appendix: 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 69bf83ad71)