spring-projects/spring-framework · error · IntrospectionException

Bad indexed write method arg count: {}

Error message

Bad indexed write method arg count: {}

What it means

Thrown as java.beans.IntrospectionException by PropertyDescriptorUtils.findIndexedPropertyType when an indexed write method does not have exactly two parameters. Indexed setters must take exactly (int index, value) - i.e. two parameters with the first being the int index.

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 69bf83ad71)

Solutions

  1. Make the indexed setter take exactly two parameters, the first being int: void setXxx(int i, Type value).
  2. If the property is not indexed, register it as a simple setter (1 param) instead.
  3. Correct or regenerate the offending class.

Example fix

// before
public void setItem(Item value); // wrong arity for indexed setter

// after
public void setItem(int i, Item value);
Defensive patterns

Strategy: validation

Validate before calling

if (indexedWriteMethod != null && indexedWriteMethod.getParameterCount() != 2) {
    throw new IllegalArgumentException("indexed setter must take 2 args: " + indexedWriteMethod);
}

Type guard

static boolean validIndexedWriteMethod(Method m) {
    return m != null && m.getParameterCount() == 2 && m.getParameterTypes()[0] == int.class;
}

Prevention

When it happens

Trigger: findIndexedPropertyType called with an indexedWriteMethod whose parameter count != 2 (e.g. 1, 3, or 0 params).

Common situations: A setXxx method with wrong arity being treated as an indexed setter, a simple setter misregistered as indexed, or generated code emitting malformed indexed setters.

Related errors


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