spring-projects/spring-framework · error · IntrospectionException

Bad indexed write method arg count: ${indexedWriteMethod}

Error message

Bad indexed write method arg count: ${indexedWriteMethod}

What it means

IntrospectionException from PropertyDescriptorUtils.findIndexedPropertyType when an indexed write method does not take exactly 2 parameters. Indexed setters must take (int index, <value-type> value); any other arity is invalid.

Source

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

		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);
			}
			if (indexedPropertyType != null) {
				if (indexedPropertyType.isAssignableFrom(params[1])) {
					// Write method's property type potentially more specific
					indexedPropertyType = params[1];
				}
				else if (params[1].isAssignableFrom(indexedPropertyType)) {
					// Proceed with read method's property type
				}
				else {
					throw new IntrospectionException("Type mismatch between indexed read and write methods: " +
							indexedReadMethod + " - " + indexedWriteMethod);
				}
			}
			else {

View on GitHub (pinned to e8729d0438)

Solutions

  1. Ensure the indexed setter takes exactly two parameters: int index then the value.
  2. If it is a simple setter, register it as writeMethod (non-indexed), not indexedWriteMethod.
  3. Rename overloaded variants to avoid misclassification.

Example fix

// before
new IndexedPropertyDescriptor("items", null,
    MyClass.class.getDeclaredMethod("setItems", String.class), null, null);

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

Strategy: validation

Validate before calling

static void assertValidIndexedWriteMethod(Method m) {
    if (m.getParameterCount() != 2) {
        throw new IllegalArgumentException("Indexed write must take 2 params: " + m);
    }
}

Type guard

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

Try / catch

try {
    return new IndexedPropertyDescriptor(name, null, null, indexedReadMethod, indexedWriteMethod);
} catch (java.beans.IntrospectionException ex) {
    if (ex.getMessage().startsWith("Bad indexed write method arg count")) {
        if (indexedWriteMethod.getParameterCount() == 1) {
            // it is a simple setter, not indexed
            return new PropertyDescriptor(name, indexedReadMethod, indexedWriteMethod);
        }
    }
    throw ex;
}

Prevention

When it happens

Trigger: Registering setItems(String) (1 arg, simple setter) or setItems(int, String, Object) (3 args) as indexedWriteMethod; or a setItems(int) single-arg variant mistaken for an indexed setter.

Common situations: Confusion between simple and indexed setters; overloaded set methods; generators producing non-standard setter arity.

Related errors


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