{"record":{"id":"f389a68c20589836","repo":"spring-projects/spring-framework","slug":"property-referenced-in-indexed-property-path-pro","errorCode":null,"errorMessage":"Property referenced in indexed property path '{propertyName}' is neither an array nor a List/Set/Collection/Iterable nor a Map; returned value was [{value}]","messagePattern":"Property referenced in indexed property path '(.+?)' is neither an array nor a List/Set/Collection/Iterable nor a Map; returned value was \\[(.+?)\\]","errorType":"exception","errorClass":"InvalidPropertyException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java","lineNumber":673,"sourceCode":"\t\t\t\t\t\tIterator<Object> it = iterable.iterator();\n\t\t\t\t\t\tboolean found = false;\n\t\t\t\t\t\tint currIndex = 0;\n\t\t\t\t\t\tfor (; it.hasNext(); currIndex++) {\n\t\t\t\t\t\t\tObject elem = it.next();\n\t\t\t\t\t\t\tif (currIndex == index) {\n\t\t\t\t\t\t\t\tvalue = elem;\n\t\t\t\t\t\t\t\tfound = true;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (!found) {\n\t\t\t\t\t\t\tthrow new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,\n\t\t\t\t\t\t\t\t\t\"Cannot get element with index \" + index + \" from Iterable of size \" +\n\t\t\t\t\t\t\t\t\t\t\tcurrIndex + \", accessed using property path '\" + propertyName + \"'\");\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\telse {\n\t\t\t\t\t\tthrow new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,\n\t\t\t\t\t\t\t\t\"Property referenced in indexed property path '\" + propertyName +\n\t\t\t\t\t\t\t\t\t\t\"' is neither an array nor a List/Set/Collection/Iterable nor a Map; \" +\n\t\t\t\t\t\t\t\t\t\t\"returned value was [\" + value + \"]\");\n\t\t\t\t\t}\n\t\t\t\t\tindexedPropertyName.append(PROPERTY_KEY_PREFIX).append(key).append(PROPERTY_KEY_SUFFIX);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn value;\n\t\t}\n\t\tcatch (InvalidPropertyException ex) {\n\t\t\tthrow ex;\n\t\t}\n\t\tcatch (IndexOutOfBoundsException ex) {\n\t\t\tthrow new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,\n\t\t\t\t\t\"Index of out of bounds in property path '\" + propertyName + \"'\", ex);\n\t\t}\n\t\tcatch (NumberFormatException | TypeMismatchException ex) {\n\t\t\tthrow new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,","sourceCodeStart":655,"sourceCodeEnd":691,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java#L655-L691","documentation":"Thrown by getPropertyValue's terminal else in the key loop: a key/index is being applied to a value that is not array, List, Set/Collection/Iterable, or Map. Reads have no container to index into, so Spring raises InvalidPropertyException including the offending value.","triggerScenarios":"getPropertyValue(\"name[0]\") where 'name' is a scalar (String, Number, custom object); reading a key off a scalar property.","commonSituations":"Mismatched read path treating a scalar as indexed; refactored property from collection to scalar without updating consumers; SpEL/property path constructed dynamically from user input.","solutions":["Drop the index/key from the read path if the property is scalar.","Change the property to an array/List/Map if indexed read is intended.","Inspect wrapper.getPropertyType(name) before issuing an indexed read.","Sanitize user-supplied property paths so indexed syntax is only used on container-typed properties."],"exampleFix":"// before\n// private String title;\nwrapper.getPropertyValue(\"title[0]\");\n\n// after\n// private List<String> titles = new ArrayList<>();\nwrapper.getPropertyValue(\"titles[0]\");","handlingStrategy":"type-guard","validationCode":"BeanWrapper w = new BeanWrapperImpl(bean);\nClass<?> type = w.getPropertyType(\"name\");\nif (!isIndexReadableType(type)) {\n    throw new IllegalArgumentException(\"'name' is not index-readable: \" + type);\n}\nreturn w.getPropertyValue(\"name[0]\");","typeGuard":"static boolean isIndexReadableType(Class<?> t) {\n    return t != null && (t.isArray() || List.class.isAssignableFrom(t)\n        || Set.class.isAssignableFrom(t) || Collection.class.isAssignableFrom(t)\n        || Iterable.class.isAssignableFrom(t) || Map.class.isAssignableFrom(t));\n}","tryCatchPattern":"try {\n    return wrapper.getPropertyValue(path);\n} catch (InvalidPropertyException ex) {\n    if (ex.getMessage().contains(\"neither an array nor a List\")) return null; // not indexable\n    throw ex;\n}","preventionTips":["Only apply indexed syntax to array/List/Set/Collection/Iterable/Map-typed properties.","Inspect getPropertyType before issuing indexed reads from dynamic paths.","Reject user-supplied paths that use index syntax on scalar properties."],"tags":["spring-beans","bean-wrapper","indexed-property","type-mismatch","read"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}