spring-projects/spring-framework · error · NullValueInNestedPathException
Cannot access indexed value in property referenced in…
Error message
Cannot access indexed value in property referenced in indexed property path '{tokens.canonicalName}': returned null What it means
Thrown by getPropertyHoldingValue when the holding value for a keyed write is null and setAutoGrowNestedPaths is false. Without auto-grow Spring cannot create the container, so it raises NullValueInNestedPathException naming the canonical path.
Solutions
- Initialize the collection/map field: e.g. private List<T> items = new ArrayList<>();.
- Call wrapper.setAutoGrowNestedPaths(true) before the write (propagated to nested accessors).
- Set the holding property to a non-null container before addressing an index/key.
- Pre-flight check getPropertyValue(base) for null and instantiate explicitly.
Example fix
// before
private List<String> items; // null
wrapper.setPropertyValue("items[0]", "a");
// after
private List<String> items = new ArrayList<>();
// or
wrapper.setAutoGrowNestedPaths(true); Defensive patterns
Strategy: validation
Validate before calling
BeanWrapper w = new BeanWrapperImpl(bean);
String base = path.substring(0, path.indexOf('['));
Object holder = w.getPropertyValue(base);
if (holder == null) {
// either initialize the field or enable autogrow
w.setAutoGrowNestedPaths(true);
}
w.setPropertyValue(path, value); Type guard
static boolean holderNotNull(BeanWrapper w, String path) {
String base = path.substring(0, path.indexOf('['));
return w.getPropertyValue(base) != null;
} Try / catch
try {
wrapper.setPropertyValue(path, value);
} catch (NullValueInNestedPathException ex) {
if (ex.getMessage().contains("returned null")) { /* initialize container or enable autogrow */ }
else throw ex;
} Prevention
- Initialize collection/map fields inline (private List<T> items = new ArrayList<>();).
- Enable setAutoGrowNestedPaths(true) when binding onto beans with null containers.
- Return empty containers from getters instead of null.
When it happens
Trigger: setProperty("items[0]", value) where getItems() returns null and autoGrowNestedPaths is disabled (the default in some contexts).
Common situations: Bean field left null with no initializer; binding into a freshly constructed bean whose collection/map fields are null; autoGrow turned off for safety; nested wrapper created without inheriting autoGrow settings.
Related errors
- Cannot access indexed value of property referenced in…
- Cannot access indexed value in property referenced in…
- Cannot set element with index
- Invalid array index in property path
- No property handler found
AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09).
Data as JSON: /api/errors/84494e4436ee035e.
Report an issue: GitHub.
Appendix: source
Thrown at spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java:386
Object propValue;
try {
propValue = getPropertyValue(getterTokens);
}
catch (NotReadablePropertyException ex) {
throw new NotWritablePropertyException(getRootClass(), this.nestedPath + tokens.canonicalName,
"Cannot access indexed value in property referenced " +
"in indexed property path '" + tokens.canonicalName + "'", ex);
}
if (propValue == null) {
// null map value case
if (isAutoGrowNestedPaths()) {
int lastKeyIndex = tokens.canonicalName.lastIndexOf('[');
getterTokens.canonicalName = tokens.canonicalName.substring(0, lastKeyIndex);
propValue = setDefaultValue(getterTokens);
}
else {
throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + tokens.canonicalName,
"Cannot access indexed value in property referenced " +
"in indexed property path '" + tokens.canonicalName + "': returned null");
}
}
return propValue;
}
private void processLocalProperty(PropertyTokenHolder tokens, PropertyValue pv) {
PropertyHandler ph = getLocalPropertyHandler(tokens.actualName);
if (ph == null || !ph.isWritable()) {
if (pv.isOptional()) {
if (logger.isDebugEnabled()) {
logger.debug("Ignoring optional value for property '" + tokens.actualName +
"' - property not found on bean class [" + getRootClass().getName() + "]");
}
return;
}
if (this.suppressNotWritablePropertyException) {View on GitHub (pinned to 69bf83ad71)