spring-projects/spring-framework · error · IllegalArgumentException
Both 'constructorArgs' and 'constructorArgTypes' need to be…
Error message
Both 'constructorArgs' and 'constructorArgTypes' need to be specified
What it means
CglibAopProxy.setConstructorArguments() (line 146) takes both the argument values and the argument types needed to pick the right constructor when the CGLIB proxy is instantiated. Passing one as null while the other is non-null is inconsistent, so Spring rejects it (line 147).
Solutions
- Supply both arrays: proxy.setConstructorArguments(args, argTypes)
- If you have no constructor arguments to pass, simply do not call setConstructorArguments at all (the default no-arg path is used)
- Ensure each entry in argTypes is the Class of the corresponding arg
Example fix
// before
proxy.setConstructorArguments(new Object[]{42}, null);
// after
proxy.setConstructorArguments(new Object[]{42}, new Class[]{int.class}); Defensive patterns
Strategy: validation
Validate before calling
if (constructorArgs == null || constructorArgTypes == null) {
throw new IllegalArgumentException("constructorArgs and constructorArgTypes must both be non-null");
} Type guard
private static boolean constructorArgsComplete(Object[] args, Class<?>[] types) {
return args != null && types != null;
} Prevention
- Pass both arrays together or omit the call entirely
- Wrap constructor-arg setup in a helper that takes paired (value,type) entries
When it happens
Trigger: Calling setConstructorArguments(args, null) or setConstructorArguments(null, types) - supplying only one of the two arrays.
Common situations: Programmatic ProxyFactory usage where you intend constructor-based proxying but wire only args or only types; refactor that dropped one of the parameters; assuming types can be inferred (they cannot safely here).
Related errors
- Number of 'constructorArgs
- An advice method can never be a constructor
- Can't determine type of bean with name
- Could not generate CGLIB subclass of
- Failed to invoke aspect constructor
AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09).
Data as JSON: /api/errors/cf1a64b7c2dd9cb7.
Report an issue: GitHub.
Appendix: source
Thrown at spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java:148
* Create a new CglibAopProxy for the given AOP configuration.
* @param config the AOP configuration as AdvisedSupport object
* @throws AopConfigException if the config is invalid. We try to throw an informative
* exception in this case, rather than let a mysterious failure happen later.
*/
public CglibAopProxy(AdvisedSupport config) throws AopConfigException {
Assert.notNull(config, "AdvisedSupport must not be null");
this.advised = config;
this.advisedDispatcher = new AdvisedDispatcher(this.advised);
}
/**
* Set constructor arguments to use for creating the proxy.
* @param constructorArgs the constructor argument values
* @param constructorArgTypes the constructor argument types
*/
public void setConstructorArguments(Object @Nullable [] constructorArgs, Class<?> @Nullable [] constructorArgTypes) {
if (constructorArgs == null || constructorArgTypes == null) {
throw new IllegalArgumentException("Both 'constructorArgs' and 'constructorArgTypes' need to be specified");
}
if (constructorArgs.length != constructorArgTypes.length) {
throw new IllegalArgumentException("Number of 'constructorArgs' (" + constructorArgs.length +
") must match number of 'constructorArgTypes' (" + constructorArgTypes.length + ")");
}
this.constructorArgs = constructorArgs;
this.constructorArgTypes = constructorArgTypes;
}
@Override
public Object getProxy() {
return buildProxy(null, false);
}
@Override
public Object getProxy(@Nullable ClassLoader classLoader) {
return buildProxy(classLoader, false);View on GitHub (pinned to 69bf83ad71)