{"record":{"id":"097bfd753b56cf9a","repo":"spring-projects/spring-framework","slug":"invalid-property-propertyname-of-bean-class","errorCode":null,"errorMessage":"Invalid property '{propertyName}' of bean class [{beanClass.getName()}]: Index of out of bounds in property path '{propertyName}'","messagePattern":"Invalid property '(.+?)' of bean class \\[(.+?)\\]: 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/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java#L669-L705","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nObject v = wrapper.getPropertyValue(\"arr[\" + requestIdx + \"]\"); // unvalidated\n\n// after\nint len = Array.getLength(wrapper.getPropertyValue(\"arr\"));\nif (requestIdx < 0 || requestIdx >= len) throw new IndexOutOfBoundsException(...);\nObject v = wrapper.getPropertyValue(\"arr[\" + requestIdx + \"]\");","handlingStrategy":"validation","validationCode":"BeanWrapper w = new BeanWrapperImpl(bean);\nObject arr = w.getPropertyValue(\"arr\");\nint len = arr == null ? 0 : (arr.getClass().isArray() ? java.lang.reflect.Array.getLength(arr)\n        : (arr instanceof List<?> l ? l.size() : -1));\nif (idx < 0 || idx >= len) throw new IndexOutOfBoundsException(\"idx=\" + idx + \" len=\" + len);\nreturn w.getPropertyValue(\"arr[\" + idx + \"]\");","typeGuard":"static boolean indexWithinBounds(Object container, int idx) {\n    if (container == null) return false;\n    if (container.getClass().isArray()) return idx >= 0 && idx < java.lang.reflect.Array.getLength(container);\n    if (container instanceof List<?> l) return idx >= 0 && idx < l.size();\n    return false;\n}","tryCatchPattern":"try {\n    return wrapper.getPropertyValue(path);\n} catch (InvalidPropertyException ex) {\n    if (ex.getCause() instanceof IndexOutOfBoundsException) return null;\n    throw ex;\n}","preventionTips":["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."],"tags":["spring-beans","bean-wrapper","index-out-of-bounds","array","read"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}