spring-projects/spring-framework · error · InvalidPropertyException
Index of out of bounds in property path '${propertyName}'
Error message
Index of out of bounds in property path '${propertyName}' What it means
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.
Source
Thrown at spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java:687
currIndex + ", accessed using property path '" + propertyName + "'");
}
}
else {
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
"Property referenced in indexed property path '" + propertyName +
"' is neither an array nor a List/Set/Collection/Iterable nor a Map; " +
"returned value was [" + value + "]");
}
indexedPropertyName.append(PROPERTY_KEY_PREFIX).append(key).append(PROPERTY_KEY_SUFFIX);
}
}
return value;
}
catch (InvalidPropertyException ex) {
throw ex;
}
catch (IndexOutOfBoundsException ex) {
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
"Index of out of bounds in property path '" + propertyName + "'", ex);
}
catch (NumberFormatException | TypeMismatchException ex) {
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
"Invalid index in property path '" + propertyName + "'", ex);
}
catch (InvocationTargetException ex) {
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
"Getter for property '" + actualName + "' threw exception", ex);
}
catch (Exception ex) {
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
"Illegal attempt to get property '" + actualName + "' threw exception", ex);
}
}
/**View on GitHub (pinned to e8729d0438)
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.
Example fix
// before
List<Integer> ids = List.of(1, 2, 3);
bean.setIds(ids);
Object v = wrapper.getPropertyValue("ids[5]"); // OOB
// after
int idx = 5;
Object v = ((List<?>) wrapper.getPropertyValue("ids")).size() > idx
? wrapper.getPropertyValue("ids[" + idx + "]") : null; Defensive patterns
Strategy: validation
Validate before calling
Object coll = wrapper.getPropertyValue(propertyName.replaceAll("\\[.*$", ""));
int idx = Integer.parseInt(propertyName.replaceAll(".*\\[|\\].*", ""));
int size = coll.getClass().isArray() ? Array.getLength(coll)
: (coll instanceof Collection<?> c ? c.size() : -1);
if (idx >= 0 && idx < size) {
wrapper.getPropertyValue(propertyName);
} Type guard
static boolean indexInBounds(Object coll, int idx) {
if (coll == null) return false;
if (coll.getClass().isArray()) return idx >= 0 && idx < Array.getLength(coll);
if (coll instanceof Collection<?> c) return idx >= 0 && idx < c.size();
return false;
} Try / catch
try { Object v = wrapper.getPropertyValue(propertyName); }
catch (InvalidPropertyException ex) { v = null; } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Reading past the end of a List/array via SpEL or BeanWrapper; binding code using untrusted indices; autoGrow disabled while expecting tolerant reads.
Related errors
- Invalid array index in property path '{tokens.canonicalName}
- Invalid list index in property path '{tokens.canonicalName}'
- Cannot get element with index {index} from Collection of siz
- Cannot get element with index {index} from Iterable of size
- No property handler found
AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04).
Data as JSON: /data/errors/c0e98fb08cfad0dc.json.
Report an issue: GitHub.