{"id":"c0e98fb08cfad0dc","repo":"spring-projects/spring-framework","slug":"index-of-out-of-bounds-in-property-path-propert","errorCode":null,"errorMessage":"Index of out of bounds in property path '${propertyName}'","messagePattern":"Index of out of bounds in property path '(.+?)'","errorType":"exception","errorClass":"InvalidPropertyException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java","lineNumber":687,"sourceCode":"\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,\n\t\t\t\t\t\"Invalid index in property path '\" + propertyName + \"'\", ex);\n\t\t}\n\t\tcatch (InvocationTargetException ex) {\n\t\t\tthrow new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,\n\t\t\t\t\t\"Getter for property '\" + actualName + \"' threw exception\", ex);\n\t\t}\n\t\tcatch (Exception ex) {\n\t\t\tthrow new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,\n\t\t\t\t\t\"Illegal attempt to get property '\" + actualName + \"' threw exception\", ex);\n\t\t}\n\t}\n\n\n\t/**","sourceCodeStart":669,"sourceCodeEnd":705,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java#L669-L705","documentation":"Catch block in getPropertyValue(PropertyTokenHolder) for IndexOutOfBoundsException thrown while applying keys (e.g. Array.get or List.get with a bad index that escaped the earlier Collection-size check). Spring rewraps it as InvalidPropertyException 'Index of out of bounds'. Note the literal message in source is 'Index of out of bounds' (a pre-existing typo for 'out of bounds') followed by the property path.","triggerScenarios":"getProperty(\"items[99]\") on a List/array of size 5 with autoGrow off (the generic Collection guard does not cover List/array direct access); reading an array index beyond its length.","commonSituations":"Reading past the end of a List/array via SpEL or BeanWrapper; binding code using untrusted indices; autoGrow disabled while expecting tolerant reads.","solutions":["Validate the index against the collection size before reading.","Enable autoGrowNestedPaths (with an adequate autoGrowCollectionLimit) for read tolerance.","Pre-size or populate the collection so the index exists."],"exampleFix":"// before\nList<Integer> ids = List.of(1, 2, 3);\nbean.setIds(ids);\nObject v = wrapper.getPropertyValue(\"ids[5]\"); // OOB\n\n// after\nint idx = 5;\nObject v = ((List<?>) wrapper.getPropertyValue(\"ids\")).size() > idx\n    ? wrapper.getPropertyValue(\"ids[\" + idx + \"]\") : null;","handlingStrategy":"validation","validationCode":"Object coll = wrapper.getPropertyValue(propertyName.replaceAll(\"\\\\[.*$\", \"\"));\nint idx = Integer.parseInt(propertyName.replaceAll(\".*\\\\[|\\\\].*\", \"\"));\nint size = coll.getClass().isArray() ? Array.getLength(coll)\n    : (coll instanceof Collection<?> c ? c.size() : -1);\nif (idx >= 0 && idx < size) {\n    wrapper.getPropertyValue(propertyName);\n}","typeGuard":"static boolean indexInBounds(Object coll, int idx) {\n    if (coll == null) return false;\n    if (coll.getClass().isArray()) return idx >= 0 && idx < Array.getLength(coll);\n    if (coll instanceof Collection<?> c) return idx >= 0 && idx < c.size();\n    return false;\n}","tryCatchPattern":"try { Object v = wrapper.getPropertyValue(propertyName); }\ncatch (InvalidPropertyException ex) { v = null; }","preventionTips":["Bound-check indices against List/array length before reading.","Enable autoGrowNestedPaths only when read-side growth is desired.","Sanitize untrusted indices before constructing property paths."],"tags":["spring-beans","bean-wrapper","indexed-property","index-out-of-bounds"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}