{"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/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java#L595-L631","documentation":"Raised at the start of the key-application loop in getPropertyValue(PropertyTokenHolder): the property handler is readable and ph.getValue() was obtained, but it is null and the path still has index/map keys to apply. With autoGrowNestedPaths off, Spring cannot dereference a null, so it throws NullValueInNestedPathException 'returned null'. The propertyName in the message is the full indexed path.","triggerScenarios":"getProperty(\"items[0]\") where getItems() returns null; reading 'config[\"key\"]' when getConfig() is null; a SpEL/BeanWrapper read against a freshly created bean with uninitialized collection fields.","commonSituations":"Reading nested indexed values before the collection has been populated; DTOs with nullable collection fields; disabling autoGrowNestedPaths while still expecting tolerant reads.","solutions":["Initialize the collection/map/array field (field initializer or constructor).","Enable wrapper.setAutoGrowNestedPaths(true) if you want tolerant auto-creation on read.","Guard the read with a null check on the enclosing property first."],"exampleFix":"// before\npublic class Bag { private Map<String,String> props; ... } // null\nObject v = wrapper.getPropertyValue(\"props['k']\");\n\n// after\npublic class Bag { private Map<String,String> props = new HashMap<>(); ... }","handlingStrategy":"validation","validationCode":"String base = propertyName.replaceAll(\"\\\\[.*$\", \"\");\nObject holder = wrapper.getPropertyValue(base);\nif (holder != null || wrapper.isAutoGrowNestedPaths()) {\n    wrapper.getPropertyValue(propertyName);\n}","typeGuard":"static boolean holderNotNull(BeanWrapper bw, String path) {\n    return bw.getPropertyValue(path.replaceAll(\"\\\\[.*$\", \"\")) != null;\n}","tryCatchPattern":"try { Object v = wrapper.getPropertyValue(propertyName); }\ncatch (NullValueInNestedPathException ex) { v = null; }","preventionTips":["Initialize collection/map/array fields before reads.","Enable autoGrowNestedPaths for tolerant reads.","Null-check the enclosing property before indexed reads."],"tags":["spring-beans","bean-wrapper","indexed-property","null-value","auto-grow"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}