spring-projects/spring-framework · error · IntrospectionException
Bad read method arg count: ${readMethod}
Error message
Bad read method arg count: ${readMethod} What it means
IntrospectionException thrown by PropertyDescriptorUtils.findPropertyType when a candidate read method takes any parameters. The JavaBean contract requires read methods (getters) to have zero parameters; a getter with parameters is not a valid property accessor and PropertyDescriptor construction cannot proceed.
Source
Thrown at spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java:155
}
// See java.beans.PropertyDescriptor#PropertyDescriptor(PropertyDescriptor)
target.setPropertyEditorClass(source.getPropertyEditorClass());
target.setBound(source.isBound());
target.setConstrained(source.isConstrained());
}
/**
* See {@link java.beans.PropertyDescriptor#findPropertyType}.
*/
public static @Nullable Class<?> findPropertyType(@Nullable Method readMethod, @Nullable Method writeMethod)
throws IntrospectionException {
Class<?> propertyType = null;
if (readMethod != null) {
if (readMethod.getParameterCount() != 0) {
throw new IntrospectionException("Bad read method arg count: " + readMethod);
}
propertyType = readMethod.getReturnType();
if (propertyType == void.class) {
throw new IntrospectionException("Read method returns void: " + readMethod);
}
}
if (writeMethod != null) {
Class<?>[] params = writeMethod.getParameterTypes();
if (params.length != 1) {
throw new IntrospectionException("Bad write method arg count: " + writeMethod);
}
if (propertyType != null) {
if (propertyType.isAssignableFrom(params[0])) {
// Write method's property type potentially more specific
propertyType = params[0];
}
else if (params[0].isAssignableFrom(propertyType)) {View on GitHub (pinned to e8729d0438)
Solutions
- If the method is an indexed accessor, register it as indexedReadMethod on an IndexedPropertyDescriptor (it then takes one int param).
- Remove the parameter from the getter, or rename the parameterized method so it is not mistaken for the property's read method.
- When building descriptors programmatically, pass a zero-arg method as readMethod.
Example fix
// before
new PropertyDescriptor("items", MyClass.class.getDeclaredMethod("getItems", int.class), null);
// after
new IndexedPropertyDescriptor("items", null, null,
MyClass.class.getDeclaredMethod("getItems", int.class), null); Defensive patterns
Strategy: validation
Validate before calling
// Validate a read method before constructing a descriptor
static void assertValidReadMethod(Method readMethod) {
if (readMethod.getParameterCount() != 0) {
throw new IllegalArgumentException(
"Read method must take 0 params: " + readMethod);
}
} Type guard
static boolean isValidReadMethod(Method m) {
return m != null && m.getParameterCount() == 0 && m.getReturnType() != void.class;
} Try / catch
try {
return new PropertyDescriptor(name, readMethod, writeMethod);
} catch (java.beans.IntrospectionException ex) {
if (ex.getMessage().startsWith("Bad read method arg count")) {
// re-resolve to the zero-arg variant
readMethod = Arrays.stream(clazz.getMethods())
.filter(x -> x.getName().equals(readMethod.getName()) && x.getParameterCount() == 0)
.findFirst().orElseThrow();
return new PropertyDescriptor(name, readMethod, writeMethod);
}
throw ex;
} Prevention
- Ensure getters take zero parameters.
- If indexed, register via IndexedPropertyDescriptor.
- Validate Method arity before constructing descriptors programmatically.
When it happens
Trigger: Building a PropertyDescriptor where the supplied readMethod has parameterCount != 0; happens during introspection when a getFoo(...) method is mistakenly treated as the read method for property 'foo', or when hand-constructing PropertyDescriptors.
Common situations: A class with a getFoo(int index) method intended as an indexed getter but registered as a non-indexed read method; overloaded getFoo() vs getFoo(arg); tooling that auto-derives descriptors from method names without arity checks.
Related errors
- Read method returns void: ${readMethod}
- Bean property '{propertyName}' is not readable or has an inv
- Bad write method arg count: ${writeMethod}
- Type mismatch between read and write methods: ${readMethod}
- Bad indexed read method arg count: ${indexedReadMethod}
AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04).
Data as JSON: /data/errors/17359472ba3edecd.json.
Report an issue: GitHub.