spring-projects/spring-framework · error · InvalidPropertyException

Property referenced in indexed property path

Error message

Property referenced in indexed property path '{propertyName}' is neither an array nor a List/Set/Collection/Iterable nor a Map; returned value was [{value}]

What it means

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.

Solutions

  1. Drop the index/key from the read path if the property is scalar.
  2. Change the property to an array/List/Map if indexed read is intended.
  3. Inspect wrapper.getPropertyType(name) before issuing an indexed read.
  4. Sanitize user-supplied property paths so indexed syntax is only used on container-typed properties.

Example fix

// before
// private String title;
wrapper.getPropertyValue("title[0]");

// after
// private List<String> titles = new ArrayList<>();
wrapper.getPropertyValue("titles[0]");
Defensive patterns

Strategy: type-guard

Validate before calling

BeanWrapper w = new BeanWrapperImpl(bean);
Class<?> type = w.getPropertyType("name");
if (!isIndexReadableType(type)) {
    throw new IllegalArgumentException("'name' is not index-readable: " + type);
}
return w.getPropertyValue("name[0]");

Type guard

static boolean isIndexReadableType(Class<?> t) {
    return t != null && (t.isArray() || List.class.isAssignableFrom(t)
        || Set.class.isAssignableFrom(t) || Collection.class.isAssignableFrom(t)
        || Iterable.class.isAssignableFrom(t) || Map.class.isAssignableFrom(t));
}

Try / catch

try {
    return wrapper.getPropertyValue(path);
} catch (InvalidPropertyException ex) {
    if (ex.getMessage().contains("neither an array nor a List")) return null; // not indexable
    throw ex;
}

Prevention

When it happens

Trigger: getPropertyValue("name[0]") where 'name' is a scalar (String, Number, custom object); reading a key off a scalar property.

Common situations: 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.

Related errors


AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09). Data as JSON: /api/errors/f389a68c20589836. Report an issue: GitHub.

Appendix: source

Thrown at spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java:673

						Iterator<Object> it = iterable.iterator();
						boolean found = false;
						int currIndex = 0;
						for (; it.hasNext(); currIndex++) {
							Object elem = it.next();
							if (currIndex == index) {
								value = elem;
								found = true;
								break;
							}
						}
						if (!found) {
							throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
									"Cannot get element with index " + index + " from Iterable of size " +
											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,

View on GitHub (pinned to 69bf83ad71)