spring-projects/spring-framework · error · NullValueInNestedPathException
Cannot access indexed value of property referenced in…
Error message
Cannot access indexed value of property referenced in indexed property path '{propertyName}': returned null What it means
Thrown by getPropertyValue(PropertyTokenHolder) at the start of key application: ph.getValue() returned null, tokens.keys is non-null (indexed path), and autoGrowNestedPaths is false. Reading an index/key from a null container is impossible, so Spring raises NullValueInNestedPathException.
Solutions
- Initialize the collection/map field to a non-null container.
- Guard reads with a null check on the base property before using indexed syntax.
- Enable autoGrowNestedPaths if you want reads to lazily create containers (note: autogrow on read can mutate the bean).
- Return an empty collection from the getter instead of null.
Example fix
// before
private List<String> items; // null
wrapper.getPropertyValue("items[0]");
// after
private List<String> items = new ArrayList<>();
// or
Object base = wrapper.getPropertyValue("items");
if (base == null) return null; 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) {
return null; // or w.setAutoGrowNestedPaths(true) then read
}
return w.getPropertyValue(path); Type guard
static boolean safeToReadIndexed(BeanWrapper w, String path) {
String base = path.substring(0, path.indexOf('['));
return w.getPropertyValue(base) != null;
} Try / catch
try {
return wrapper.getPropertyValue(path);
} catch (NullValueInNestedPathException ex) {
if (ex.getMessage().contains("returned null")) return null; // base container missing
throw ex;
} Prevention
- Never leave collection/map fields null; initialize to empty containers.
- Guard indexed reads with a null check on the base property.
- Avoid autoGrow-on-read unless you intend to mutate the bean during reads.
When it happens
Trigger: getPropertyValue("items[0]") where getItems() == null and autoGrow is off.
Common situations: Reading a bound form field whose backing collection is uninitialized; querying nested state on a freshly built bean; defensive read paths that assume a value exists.
Related errors
- Cannot access indexed value in property referenced in…
- Property referenced in indexed property path
- Cannot access indexed value in property referenced in…
- Cannot get element with index
- Cannot get element with index
AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09).
Data as JSON: /api/errors/fc9b4da744aa83a7.
Report an issue: GitHub.
Appendix: source
Thrown at spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java:613
}
@SuppressWarnings({"rawtypes", "unchecked"})
protected @Nullable Object getPropertyValue(PropertyTokenHolder tokens) throws BeansException {
String propertyName = tokens.canonicalName;
String actualName = tokens.actualName;
PropertyHandler ph = getLocalPropertyHandler(actualName);
if (ph == null || !ph.isReadable()) {
throw new NotReadablePropertyException(getRootClass(), this.nestedPath + propertyName);
}
try {
Object value = ph.getValue();
if (tokens.keys != null) {
if (value == null) {
if (isAutoGrowNestedPaths()) {
value = setDefaultValue(new PropertyTokenHolder(tokens.actualName));
}
else {
throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + propertyName,
"Cannot access indexed value of property referenced in indexed " +
"property path '" + propertyName + "': returned null");
}
}
StringBuilder indexedPropertyName = new StringBuilder(tokens.actualName);
// apply indexes and map keys
for (int i = 0; i < tokens.keys.length; i++) {
String key = tokens.keys[i];
if (value == null) {
throw new NullValueInNestedPathException(getRootClass(), this.nestedPath + propertyName,
"Cannot access indexed value of property referenced in indexed " +
"property path '" + propertyName + "': returned null");
}
else if (value.getClass().isArray()) {
int index = Integer.parseInt(key);
value = growArrayIfNecessary(value, index, indexedPropertyName.toString());
value = Array.get(value, index);
}View on GitHub (pinned to 69bf83ad71)