{"record":{"id":"fc9b4da744aa83a7","repo":"spring-projects/spring-framework","slug":"cannot-access-indexed-value-of-property-referenced","errorCode":null,"errorMessage":"Cannot access indexed value of property referenced in indexed property path '{propertyName}': returned null","messagePattern":"Cannot access indexed value of property referenced in indexed property path '(.+?)': returned null","errorType":"exception","errorClass":"NullValueInNestedPathException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java","lineNumber":613,"sourceCode":"\t}\n\n\t@SuppressWarnings({\"rawtypes\", \"unchecked\"})\n\tprotected @Nullable Object getPropertyValue(PropertyTokenHolder tokens) throws BeansException {\n\t\tString propertyName = tokens.canonicalName;\n\t\tString actualName = tokens.actualName;\n\t\tPropertyHandler ph = getLocalPropertyHandler(actualName);\n\t\tif (ph == null || !ph.isReadable()) {\n\t\t\tthrow new NotReadablePropertyException(getRootClass(), this.nestedPath + propertyName);\n\t\t}\n\t\ttry {\n\t\t\tObject value = ph.getValue();\n\t\t\tif (tokens.keys != null) {\n\t\t\t\tif (value == null) {\n\t\t\t\t\tif (isAutoGrowNestedPaths()) {\n\t\t\t\t\t\tvalue = setDefaultValue(new PropertyTokenHolder(tokens.actualName));\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthrow new NullValueInNestedPathException(getRootClass(), this.nestedPath + propertyName,\n\t\t\t\t\t\t\t\t\"Cannot access indexed value of property referenced in indexed \" +\n\t\t\t\t\t\t\t\t\t\t\"property path '\" + propertyName + \"': returned null\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tStringBuilder indexedPropertyName = new StringBuilder(tokens.actualName);\n\t\t\t\t// apply indexes and map keys\n\t\t\t\tfor (int i = 0; i < tokens.keys.length; i++) {\n\t\t\t\t\tString key = tokens.keys[i];\n\t\t\t\t\tif (value == null) {\n\t\t\t\t\t\tthrow new NullValueInNestedPathException(getRootClass(), this.nestedPath + propertyName,\n\t\t\t\t\t\t\t\t\"Cannot access indexed value of property referenced in indexed \" +\n\t\t\t\t\t\t\t\t\t\t\"property path '\" + propertyName + \"': returned null\");\n\t\t\t\t\t}\n\t\t\t\t\telse if (value.getClass().isArray()) {\n\t\t\t\t\t\tint index = Integer.parseInt(key);\n\t\t\t\t\t\tvalue = growArrayIfNecessary(value, index, indexedPropertyName.toString());\n\t\t\t\t\t\tvalue = Array.get(value, index);\n\t\t\t\t\t}","sourceCodeStart":595,"sourceCodeEnd":631,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java#L595-L631","documentation":"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.","triggerScenarios":"getPropertyValue(\"items[0]\") where getItems() == null and autoGrow is off.","commonSituations":"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.","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."],"exampleFix":"// before\nprivate List<String> items; // null\nwrapper.getPropertyValue(\"items[0]\");\n\n// after\nprivate List<String> items = new ArrayList<>();\n// or\nObject base = wrapper.getPropertyValue(\"items\");\nif (base == null) return null;","handlingStrategy":"validation","validationCode":"BeanWrapper w = new BeanWrapperImpl(bean);\nString base = path.substring(0, path.indexOf('['));\nObject holder = w.getPropertyValue(base);\nif (holder == null) {\n    return null; // or w.setAutoGrowNestedPaths(true) then read\n}\nreturn w.getPropertyValue(path);","typeGuard":"static boolean safeToReadIndexed(BeanWrapper w, String path) {\n    String base = path.substring(0, path.indexOf('['));\n    return w.getPropertyValue(base) != null;\n}","tryCatchPattern":"try {\n    return wrapper.getPropertyValue(path);\n} catch (NullValueInNestedPathException ex) {\n    if (ex.getMessage().contains(\"returned null\")) return null; // base container missing\n    throw ex;\n}","preventionTips":["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."],"tags":["spring-beans","bean-wrapper","indexed-property","null-value","read"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}