spring-projects/spring-framework · error · IntrospectionException

Bad indexed read method arg count: ${indexedReadMethod}

Error message

Bad indexed read method arg count: ${indexedReadMethod}

What it means

IntrospectionException from PropertyDescriptorUtils.findIndexedPropertyType when an indexed read method does not take exactly 1 parameter. Indexed getters must take exactly one argument (the int index); any other arity is invalid for an indexed accessor.

Source

Thrown at spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java:200

				propertyType = params[0];
			}
		}

		return propertyType;
	}

	/**
	 * See {@link java.beans.IndexedPropertyDescriptor#findIndexedPropertyType}.
	 */
	public static @Nullable Class<?> findIndexedPropertyType(String name, @Nullable Class<?> propertyType,
			@Nullable Method indexedReadMethod, @Nullable Method indexedWriteMethod) throws IntrospectionException {

		Class<?> indexedPropertyType = null;

		if (indexedReadMethod != null) {
			Class<?>[] params = indexedReadMethod.getParameterTypes();
			if (params.length != 1) {
				throw new IntrospectionException("Bad indexed read method arg count: " + indexedReadMethod);
			}
			if (params[0] != int.class) {
				throw new IntrospectionException("Non int index to indexed read method: " + indexedReadMethod);
			}
			indexedPropertyType = indexedReadMethod.getReturnType();
			if (indexedPropertyType == void.class) {
				throw new IntrospectionException("Indexed read method returns void: " + indexedReadMethod);
			}
		}

		if (indexedWriteMethod != null) {
			Class<?>[] params = indexedWriteMethod.getParameterTypes();
			if (params.length != 2) {
				throw new IntrospectionException("Bad indexed write method arg count: " + indexedWriteMethod);
			}
			if (params[0] != int.class) {
				throw new IntrospectionException("Non int index to indexed write method: " + indexedWriteMethod);
			}

View on GitHub (pinned to e8729d0438)

Solutions

  1. Ensure the indexed read method takes exactly one parameter (the int index).
  2. If the method is a simple getter, register it as readMethod (non-indexed), not indexedReadMethod.
  3. Rename overloaded variants to remove the ambiguity.

Example fix

// before
new IndexedPropertyDescriptor("items", null, null,
    MyClass.class.getDeclaredMethod("getItems"), null);  // 0 args

// after
new IndexedPropertyDescriptor("items", null, null,
    MyClass.class.getDeclaredMethod("getItems", int.class), null);
Defensive patterns

Strategy: validation

Validate before calling

static void assertValidIndexedReadMethod(Method m) {
    if (m.getParameterCount() != 1) {
        throw new IllegalArgumentException("Indexed read method must take 1 param: " + m);
    }
}

Type guard

static boolean isValidIndexedReadMethod(Method m) {
    return m != null && m.getParameterCount() == 1;
}

Try / catch

try {
    return new IndexedPropertyDescriptor(name, null, null, indexedReadMethod, indexedWriteMethod);
} catch (java.beans.IntrospectionException ex) {
    if (ex.getMessage().startsWith("Bad indexed read method arg count")) {
        // re-resolve to the 1-arg variant
        indexedReadMethod = Arrays.stream(clazz.getMethods())
            .filter(x -> x.getName().equals(indexedReadMethod.getName()) && x.getParameterCount() == 1)
            .findFirst().orElseThrow();
    }
    throw ex;
}

Prevention

When it happens

Trigger: Registering a method as indexedReadMethod whose parameter count is 0 or >=2; e.g. getItems() (no index) or getItems(int, int) passed to an IndexedPropertyDescriptor.

Common situations: Confusion between simple getter (0 params) and indexed getter (1 param); overloaded indexed accessors; tooling misclassifying methods.

Related errors


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