{"id":"8cbbc014ddc90410","repo":"spring-projects/spring-framework","slug":"auto-growing-not-allowed-with-private-constructor","errorCode":null,"errorMessage":"Auto-growing not allowed with private constructor: ${ctor}","messagePattern":"Auto-growing not allowed with private constructor: (.+?)","errorType":"exception","errorClass":"IllegalAccessException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java","lineNumber":894,"sourceCode":"\t}\n\n\tprivate Object newValue(Class<?> type, @Nullable TypeDescriptor desc, String name) {\n\t\ttry {\n\t\t\tif (type.isArray()) {\n\t\t\t\treturn createArray(type);\n\t\t\t}\n\t\t\telse if (Collection.class.isAssignableFrom(type)) {\n\t\t\t\tTypeDescriptor elementDesc = (desc != null ? desc.getElementTypeDescriptor() : null);\n\t\t\t\treturn CollectionFactory.createCollection(type, (elementDesc != null ? elementDesc.getType() : null), 16);\n\t\t\t}\n\t\t\telse if (Map.class.isAssignableFrom(type)) {\n\t\t\t\tTypeDescriptor keyDesc = (desc != null ? desc.getMapKeyTypeDescriptor() : null);\n\t\t\t\treturn CollectionFactory.createMap(type, (keyDesc != null ? keyDesc.getType() : null), 16);\n\t\t\t}\n\t\t\telse {\n\t\t\t\tConstructor<?> ctor = type.getDeclaredConstructor();\n\t\t\t\tif (Modifier.isPrivate(ctor.getModifiers())) {\n\t\t\t\t\tthrow new IllegalAccessException(\"Auto-growing not allowed with private constructor: \" + ctor);\n\t\t\t\t}\n\t\t\t\treturn BeanUtils.instantiateClass(ctor);\n\t\t\t}\n\t\t}\n\t\tcatch (Throwable ex) {\n\t\t\tthrow new NullValueInNestedPathException(getRootClass(), this.nestedPath + name,\n\t\t\t\t\t\"Could not instantiate property type [\" + type.getName() + \"] to auto-grow nested property path\", ex);\n\t\t}\n\t}\n\n\t/**\n\t * Create the array for the given array type.\n\t * @param arrayType the desired type of the target array\n\t * @return a new array instance\n\t */\n\tprivate static Object createArray(Class<?> arrayType) {\n\t\tAssert.notNull(arrayType, \"Array type must not be null\");\n\t\tClass<?> componentType = arrayType.componentType();","sourceCodeStart":876,"sourceCodeEnd":912,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java#L876-L912","documentation":"An IllegalAccessException with this message is thrown inside newValue() when auto-growing needs to instantiate a nested bean but its only no-arg constructor is private. Spring explicitly refuses private constructors for auto-grow (unlike BeanUtils.instantiateClass, which would make it accessible). The thrown IllegalAccessException is then caught by the surrounding catch(Throwable) and re-wrapped into a NullValueInNestedPathException (error 143) as the cause.","triggerScenarios":"autoGrowNestedPaths=true, nested property value is null, the property type has a private no-arg constructor (common with singletons, builders, or classes designed with only a public arg-taking constructor plus a private default). Reached via AbstractNestablePropertyAccessor.java:892-895.","commonSituations":"Auto-growing into a singleton-style type, a class with only public MyType(String)/private MyType(), or a nested type from a third-party library that hides its default constructor. Config binding into such a type.","solutions":["Add a non-private (public or package-private) no-arg constructor to the nested type so auto-grow can call it.","Disable auto-grow and pre-initialize the nested field with a properly constructed instance.","Provide a factory method / @Bean and inject the instance instead of relying on Spring to auto-grow it.","If you cannot change the class, wrap it in a holder type whose constructor instantiates the target explicitly."],"exampleFix":"// before\npublic class Address { private Address() {} public Address(String s) {} }\n// auto-grow fails: private no-arg ctor\n\n// after\npublic class Address { public Address() {} public Address(String s) {} }","handlingStrategy":"validation","validationCode":"// Verify the nested type has a non-private no-arg constructor before enabling auto-grow\nClass<?> type = wrapper.getPropertyType(propName);\nif (type != null) {\n  Constructor<?> c = type.getDeclaredConstructor();\n  if (Modifier.isPrivate(c.getModifiers())) {\n    // do not enable auto-grow; set the value manually\n  }\n}","typeGuard":"public static boolean hasAutoGrowFriendlyCtor(Class<?> type) {\n  try {\n    Constructor<?> c = type.getDeclaredConstructor();\n    return !Modifier.isPrivate(c.getModifiers());\n  } catch (NoSuchMethodException e) { return false; }\n}","tryCatchPattern":"try {\n  wrapper.setAutoGrowNestedPaths(true);\n  wrapper.setPropertyValue(path, value);\n} catch (NullValueInNestedPathException e) {\n  Throwable cause = e.getCause();\n  if (cause instanceof IllegalAccessException) { /* private ctor: init manually */ }\n}","preventionTips":["Ensure nested types have a non-private no-arg constructor.","Disable auto-grow for types whose constructors are intentionally hidden.","Pre-initialize nested fields when the type is a singleton/builder pattern."],"tags":["spring-beans","bean-wrapper","auto-grow","private-constructor","instantiation"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}