spring-projects/spring-framework · error · InvalidPropertyException
Invalid property '{propertyName}' of bean class [{beanClass.
Error message
Invalid property '{propertyName}' of bean class [{beanClass.getName()}]: Index of out of bounds in property path '{propertyName}' What it means
Thrown by getPropertyValue when applying an index to an array or List raises IndexOutOfBoundsException (e.g. autoGrow off, or beyond limit, or a Set/Collection short-circuit already handled separately). It is wrapped as InvalidPropertyException with bean class context and the original exception as cause.
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 69bf83ad71)
Solutions
- Bounds-check the index against Array.getLength / list.size() before reading.
- If the index is valid but the container is short, pre-size the container or switch to a Map.
- Catch InvalidPropertyException at the binding boundary and return a 400 / field error instead of propagating.
- Validate incoming indices in a custom Validator.
Example fix
// before
Object v = wrapper.getPropertyValue("arr[" + requestIdx + "]"); // unvalidated
// after
int len = Array.getLength(wrapper.getPropertyValue("arr"));
if (requestIdx < 0 || requestIdx >= len) throw new IndexOutOfBoundsException(...);
Object v = wrapper.getPropertyValue("arr[" + requestIdx + "]"); Defensive patterns
Strategy: validation
Validate before calling
BeanWrapper w = new BeanWrapperImpl(bean);
Object arr = w.getPropertyValue("arr");
int len = arr == null ? 0 : (arr.getClass().isArray() ? java.lang.reflect.Array.getLength(arr)
: (arr instanceof List<?> l ? l.size() : -1));
if (idx < 0 || idx >= len) throw new IndexOutOfBoundsException("idx=" + idx + " len=" + len);
return w.getPropertyValue("arr[" + idx + "]"); Type guard
static boolean indexWithinBounds(Object container, int idx) {
if (container == null) return false;
if (container.getClass().isArray()) return idx >= 0 && idx < java.lang.reflect.Array.getLength(container);
if (container instanceof List<?> l) return idx >= 0 && idx < l.size();
return false;
} Try / catch
try {
return wrapper.getPropertyValue(path);
} catch (InvalidPropertyException ex) {
if (ex.getCause() instanceof IndexOutOfBoundsException) return null;
throw ex;
} Prevention
- Bounds-check against current length/size before indexed reads.
- Catch InvalidPropertyException at the binding boundary and map to a field error / 400.
- Validate indices from request parameters with a Validator.
When it happens
Trigger: getPropertyValue("arr[10]") on an array of length <= 10 with autoGrow off (reads never auto-grow arrays past the limit without autoGrow enabled); list.get(10) on a smaller list.
Common situations: Reading bound array/list fields with client-supplied indices; autoGrow not enabled for reads; index from request exceeding actual size; off-by-one in computed index.
Related errors
- Invalid array 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
- Invalid list index in property path '{tokens.canonicalName}'
- Cannot access indexed value of property referenced in indexe
AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09).
Data as JSON: /api/errors/097bfd753b56cf9a.
Report an issue: GitHub.