spring-projects/spring-framework · error · IntrospectionException

Indexed read method returns void: {}

Error message

Indexed read method returns void: {}

What it means

Thrown as java.beans.IntrospectionException by PropertyDescriptorUtils.findIndexedPropertyType when an indexed read method returns void. An indexed getter must return the element type, so a void return makes the indexed property type unresolvable.

Source

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

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

View on GitHub (pinned to 69bf83ad71)

Solutions

  1. Make the indexed getter return the element type: Type getXxx(int i).
  2. Rename the void method so it is not picked up as an indexed getter.
  3. Regenerate the offending class with correct return types.

Example fix

// before
public void getItems(int i); // void indexed getter

// after
public Item getItems(int i);
Defensive patterns

Strategy: validation

Validate before calling

if (indexedReadMethod != null && indexedReadMethod.getReturnType() == void.class) {
    throw new IllegalArgumentException("indexed getter returns void: " + indexedReadMethod);
}

Type guard

static boolean indexedGetterReturnsValue(Method m) {
    return m != null && m.getParameterCount() == 1 && m.getParameterTypes()[0] == int.class
        && m.getReturnType() != void.class;
}

Prevention

When it happens

Trigger: findIndexedPropertyType called with an indexedReadMethod whose getReturnType() == void.class (e.g. void getXxx(int i)).

Common situations: A void-returning method named getXxx(int) misregistered as an indexed getter, generated code emitting void indexed accessors, or a typo.

Related errors


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