spring-projects/spring-framework · error · NullValueInNestedPathException

Could not instantiate property type [${type.getName()}] to a

Error message

Could not instantiate property type [${type.getName()}] to auto-grow nested property path

What it means

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.

Source

Thrown at spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java:900

			}
			else if (Collection.class.isAssignableFrom(type)) {
				TypeDescriptor elementDesc = (desc != null ? desc.getElementTypeDescriptor() : null);
				return CollectionFactory.createCollection(type, (elementDesc != null ? elementDesc.getType() : null), 16);
			}
			else if (Map.class.isAssignableFrom(type)) {
				TypeDescriptor keyDesc = (desc != null ? desc.getMapKeyTypeDescriptor() : null);
				return CollectionFactory.createMap(type, (keyDesc != null ? keyDesc.getType() : null), 16);
			}
			else {
				Constructor<?> ctor = type.getDeclaredConstructor();
				if (Modifier.isPrivate(ctor.getModifiers())) {
					throw new IllegalAccessException("Auto-growing not allowed with private constructor: " + ctor);
				}
				return BeanUtils.instantiateClass(ctor);
			}
		}
		catch (Throwable ex) {
			throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + name,
					"Could not instantiate property type [" + type.getName() + "] to auto-grow nested property path", ex);
		}
	}

	/**
	 * Create the array for the given array type.
	 * @param arrayType the desired type of the target array
	 * @return a new array instance
	 */
	private static Object createArray(Class<?> arrayType) {
		Assert.notNull(arrayType, "Array type must not be null");
		Class<?> componentType = arrayType.componentType();
		if (componentType.isArray()) {
			Object array = Array.newInstance(componentType, 1);
			Array.set(array, 0, createArray(componentType));
			return array;
		}
		else {

View on GitHub (pinned to e8729d0438)

Solutions

  1. Inspect the wrapped cause (getCause()) of the NullValueInNestedPathException to identify the real reason (private ctor, abstract, thrown exception, etc.).
  2. Ensure the nested type is concrete with an accessible no-arg constructor that does not throw.
  3. Disable autoGrowNestedPaths and supply a fully-constructed instance on the target.
  4. For records/immutable types, do not rely on auto-grow; construct them explicitly before binding.

Example fix

// before
public class Address { public Address() { throw new IllegalStateException(); } }
// auto-grow wraps the ctor failure into NullValueInNestedPathException

// after
public class Address { public Address() {} }
order.setAddress(new Address()); // pre-init instead of auto-grow
Defensive patterns

Strategy: try-catch

Validate before calling

// Smoke-test instantiation of the nested type before enabling auto-grow
Class<?> type = wrapper.getPropertyType(propName);
if (type != null) {
  Constructor<?> c = type.getDeclaredConstructor();
  if (!Modifier.isPrivate(c.getModifiers())) c.newInstance(); // throws? then don't auto-grow
}

Type guard

public static boolean isAutoInstantiable(Class<?> type) {
  try {
    int mod = type.getDeclaredConstructor().getModifiers();
    return !type.isInterface() && !Modifier.isAbstract(mod)
        && !Modifier.isPrivate(mod);
  } catch (Exception e) { return false; }
}

Try / catch

try {
  wrapper.setPropertyValue(path, value);
} catch (NullValueInNestedPathException e) {
  // e.getCause() reveals private-ctor / abstract / thrown exception; handle each
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04). Data as JSON: /data/errors/3c90d2a0f785fd4d.json. Report an issue: GitHub.