spring-projects/spring-framework · error · IntrospectionException

Non int index to indexed write method: ${indexedWriteMethod}

Error message

Non int index to indexed write method: ${indexedWriteMethod}

What it means

IntrospectionException from PropertyDescriptorUtils.findIndexedPropertyType when the first parameter of an indexed write method is not int. The JavaBean spec requires the index to be primitive int; long, Integer, or other types are rejected, mirroring [174] for the write path.

Source

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

			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 {
				indexedPropertyType = params[1];
			}
		}

View on GitHub (pinned to e8729d0438)

Solutions

  1. Change the first parameter of the indexed setter to primitive int.
  2. If long indexing is required, abandon IndexedPropertyDescriptor and use a normal accessor.
  3. Regenerate code producing non-int indices.

Example fix

// before
public void setItems(long index, String value) { ... }

// after
public void setItems(int index, String value) { ... }
Defensive patterns

Strategy: type-guard

Validate before calling

static void assertIntIndexOnWrite(Method indexedWriteMethod) {
    if (indexedWriteMethod.getParameterTypes()[0] != int.class) {
        throw new IllegalArgumentException("Indexed write index must be int: " + indexedWriteMethod);
    }
}

Type guard

static boolean indexedWriteHasIntIndex(Method m) {
    Class<?>[] p = m.getParameterTypes();
    return p.length == 2 && p[0] == int.class;
}

Try / catch

try {
    return new IndexedPropertyDescriptor(name, null, null, indexedReadMethod, indexedWriteMethod);
} catch (java.beans.IntrospectionException ex) {
    if (ex.getMessage().startsWith("Non int index to indexed write")) {
        log.error("Change {} first param to int", indexedWriteMethod);
    }
    throw ex;
}

Prevention

When it happens

Trigger: An indexed setter declared setItems(long index, String value) or setItems(Integer, String) being registered as indexedWriteMethod.

Common situations: Long-indexed collections; boxed Integer indices from generated code; non-int index types from interop.

Related errors


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