spring-projects/spring-framework · error · InvalidPropertyException

Invalid index in property path '${propertyName}'

Error message

Invalid index in property path '${propertyName}'

What it means

Catch block in getPropertyValue(PropertyTokenHolder) for NumberFormatException or TypeMismatchException raised while parsing a bracket token as an integer index (e.g. 'items[abc]' or a non-numeric map key where a numeric index was expected). Spring rewraps it as InvalidPropertyException 'Invalid index in property path'.

Source

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

						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);
		}
	}


	/**
	 * Return the {@link PropertyHandler} for the specified {@code propertyName}, navigating
	 * if necessary. Return {@code null} if not found rather than throwing an exception.
	 * @param propertyName the property to obtain the descriptor for
	 * @return the property descriptor for the specified property,

View on GitHub (pinned to e8729d0438)

Solutions

  1. Ensure bracket tokens for array/List paths are valid non-negative integers.
  2. Validate/sanitize externally supplied property paths before passing them to BeanWrapper.
  3. For Map keys that are not integers, make sure the property is actually a Map, not a List/array.

Example fix

// before
Object v = wrapper.getPropertyValue("items[" + userInput + "]"); // userInput='abc'

// after
if (!userInput.matches("\\d+")) throw new IllegalArgumentException("bad index");
Object v = wrapper.getPropertyValue("items[" + userInput + "]");
Defensive patterns

Strategy: validation

Validate before calling

String token = propertyName.replaceAll(".*\\[|\\].*$", "");
if (token.matches("-?\\d+")) {
    wrapper.getPropertyValue(propertyName);
}

Type guard

static boolean isIntegerIndex(String path) {
    String t = path.replaceAll(".*\\[|\\].*$", "");
    return t.matches("-?\\d+");
}

Try / catch

try { Object v = wrapper.getPropertyValue(propertyName); }
catch (InvalidPropertyException ex) { /* malformed index token */ }

Prevention

When it happens

Trigger: getProperty("items[abc]") where the value is an array/List (Integer.parseInt('abc') fails); a malformed bracket expression like 'list[]' or 'list[1.5]'; binding a non-integer token into an indexed List path.

Common situations: User-supplied property paths with bad bracket content; templating bugs that produce non-numeric indices; SpEL path construction errors.

Related errors


AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04). Data as JSON: /data/errors/677fda1bcf52079a.json. Report an issue: GitHub.