{"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/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-aop/src/main/java/org/springframework/aop/framework/CglibAopProxy.java#L130-L166","documentation":"Thrown by CglibAopProxy.setConstructorArguments when exactly one of constructorArgs / constructorArgTypes is null. To instantiate the CGLIB proxy subclass via a parameterized constructor, CGLIB needs both the argument values and their corresponding types; passing one without the other is ambiguous. Spring rejects the half-specified state immediately.","triggerScenarios":"Programmatically calling cglibProxy.setConstructorArguments(args, null) or (null, types); building a CGLIB proxy for a class with no no-arg constructor and supplying only values or only types; reflective wiring that drops one array.","commonSituations":"Custom ProxyFactory usage targeting a class whose only constructor takes arguments; integrating with a factory that constructs proxies with specific ctor args; forgetting to populate the second array in a builder pattern.","solutions":["Supply both arrays: setConstructorArguments(new Object[]{...}, new Class<?>[]{...}) with matching, non-null values.","If the target class has a no-arg constructor, omit setConstructorArguments entirely (the default path uses enhancer.create()).","Ensure the calling code populates both arrays from the same source of truth so neither stays null."],"exampleFix":"// before\ncglibProxy.setConstructorArguments(new Object[]{42L, \"x\"}, null);  // types missing\n\n// after\ncglibProxy.setConstructorArguments(\n  new Object[]{42L, \"x\"},\n  new Class<?>[]{long.class, String.class});","handlingStrategy":"validation","validationCode":"if (constructorArgs == null || constructorArgTypes == null) {\n  throw new IllegalArgumentException(\"Both constructorArgs and constructorArgTypes must be non-null\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass both arrays together from a single paired source.","If the target class has a no-arg constructor, omit setConstructorArguments entirely.","Unit-test the programmatic proxy construction path."],"tags":["spring-aop","cglib","constructor","validation"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}