{"record":{"id":"cf1a64b7c2dd9cb7","repo":"spring-projects/spring-framework","slug":"both-constructorargs-and-constructorargtypes-n","errorCode":null,"errorMessage":"Both 'constructorArgs' and 'constructorArgTypes' need to be specified","messagePattern":"Both 'constructorArgs' and 'constructorArgTypes' need to be specified","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java","lineNumber":148,"sourceCode":"\t * Create a new CglibAopProxy for the given AOP configuration.\n\t * @param config the AOP configuration as AdvisedSupport object\n\t * @throws AopConfigException if the config is invalid. We try to throw an informative\n\t * exception in this case, rather than let a mysterious failure happen later.\n\t */\n\tpublic CglibAopProxy(AdvisedSupport config) throws AopConfigException {\n\t\tAssert.notNull(config, \"AdvisedSupport must not be null\");\n\t\tthis.advised = config;\n\t\tthis.advisedDispatcher = new AdvisedDispatcher(this.advised);\n\t}\n\n\t/**\n\t * Set constructor arguments to use for creating the proxy.\n\t * @param constructorArgs the constructor argument values\n\t * @param constructorArgTypes the constructor argument types\n\t */\n\tpublic void setConstructorArguments(Object @Nullable [] constructorArgs, Class<?> @Nullable [] constructorArgTypes) {\n\t\tif (constructorArgs == null || constructorArgTypes == null) {\n\t\t\tthrow new IllegalArgumentException(\"Both 'constructorArgs' and 'constructorArgTypes' need to be specified\");\n\t\t}\n\t\tif (constructorArgs.length != constructorArgTypes.length) {\n\t\t\tthrow new IllegalArgumentException(\"Number of 'constructorArgs' (\" + constructorArgs.length +\n\t\t\t\t\t\") must match number of 'constructorArgTypes' (\" + constructorArgTypes.length + \")\");\n\t\t}\n\t\tthis.constructorArgs = constructorArgs;\n\t\tthis.constructorArgTypes = constructorArgTypes;\n\t}\n\n\n\t@Override\n\tpublic Object getProxy() {\n\t\treturn buildProxy(null, false);\n\t}\n\n\t@Override\n\tpublic Object getProxy(@Nullable ClassLoader classLoader) {\n\t\treturn buildProxy(classLoader, false);","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java#L130-L166","documentation":"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).","triggerScenarios":"Calling setConstructorArguments(args, null) or setConstructorArguments(null, types) - supplying only one of the two arrays.","commonSituations":"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).","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"],"exampleFix":"// before\nproxy.setConstructorArguments(new Object[]{42}, null);\n\n// after\nproxy.setConstructorArguments(new Object[]{42}, new Class[]{int.class});","handlingStrategy":"validation","validationCode":"if (constructorArgs == null || constructorArgTypes == null) {\n  throw new IllegalArgumentException(\"constructorArgs and constructorArgTypes must both be non-null\");\n}","typeGuard":"private static boolean constructorArgsComplete(Object[] args, Class<?>[] types) {\n  return args != null && types != null;\n}","tryCatchPattern":null,"preventionTips":["Pass both arrays together or omit the call entirely","Wrap constructor-arg setup in a helper that takes paired (value,type) entries"],"tags":["spring-aop","cglib","constructor","config"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}