{"id":"3c90d2a0f785fd4d","repo":"spring-projects/spring-framework","slug":"could-not-instantiate-property-type-type-getnam","errorCode":null,"errorMessage":"Could not instantiate property type [${type.getName()}] to auto-grow nested property path","messagePattern":"Could not instantiate property type \\[(.+?)\\] to auto-grow nested property path","errorType":"exception","errorClass":"NullValueInNestedPathException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java","lineNumber":900,"sourceCode":"\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();\n\t\tif (componentType.isArray()) {\n\t\t\tObject array = Array.newInstance(componentType, 1);\n\t\t\tArray.set(array, 0, createArray(componentType));\n\t\t\treturn array;\n\t\t}\n\t\telse {","sourceCodeStart":882,"sourceCodeEnd":918,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java#L882-L918","documentation":"Thrown as NullValueInNestedPathException (wrapping the root cause) when newValue() cannot create the default instance for auto-growing the nested path. It is the catch-all for any Throwable from the instantiation attempt at AbstractNestablePropertyAccessor.java:899-902, including the private-constructor IllegalAccessException, abstract types, exceptions thrown by the constructor, or classloading failures.","triggerScenarios":"autoGrowNestedPaths=true and the property type cannot be instantiated: private no-arg constructor (error 142), abstract class/interface chosen as the element type, constructor that throws, missing class definition, or array/collection creation errors.","commonSituations":"Auto-growing into an abstract type, a record with required components and no canonical-compatible default, a type whose constructor throws, or a shaded/missing dependency class. Appears during Spring binding or BeanWrapper-driven population.","solutions":["Inspect the wrapped cause (getCause()) of the NullValueInNestedPathException to identify the real reason (private ctor, abstract, thrown exception, etc.).","Ensure the nested type is concrete with an accessible no-arg constructor that does not throw.","Disable autoGrowNestedPaths and supply a fully-constructed instance on the target.","For records/immutable types, do not rely on auto-grow; construct them explicitly before binding."],"exampleFix":"// before\npublic class Address { public Address() { throw new IllegalStateException(); } }\n// auto-grow wraps the ctor failure into NullValueInNestedPathException\n\n// after\npublic class Address { public Address() {} }\norder.setAddress(new Address()); // pre-init instead of auto-grow","handlingStrategy":"try-catch","validationCode":"// Smoke-test instantiation of the nested type before enabling auto-grow\nClass<?> type = wrapper.getPropertyType(propName);\nif (type != null) {\n  Constructor<?> c = type.getDeclaredConstructor();\n  if (!Modifier.isPrivate(c.getModifiers())) c.newInstance(); // throws? then don't auto-grow\n}","typeGuard":"public static boolean isAutoInstantiable(Class<?> type) {\n  try {\n    int mod = type.getDeclaredConstructor().getModifiers();\n    return !type.isInterface() && !Modifier.isAbstract(mod)\n        && !Modifier.isPrivate(mod);\n  } catch (Exception e) { return false; }\n}","tryCatchPattern":"try {\n  wrapper.setPropertyValue(path, value);\n} catch (NullValueInNestedPathException e) {\n  // e.getCause() reveals private-ctor / abstract / thrown exception; handle each\n}","preventionTips":["Read the wrapped cause to classify the failure (private ctor, abstract, thrown).","Keep nested types concrete with non-throwing accessible no-arg constructors.","Prefer explicit construction over auto-grow for types with construction invariants."],"tags":["spring-beans","bean-wrapper","auto-grow","instantiation","wrapping"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}