spring-projects/spring-framework · error · IntrospectionException
Bad write method arg count: ${writeMethod}
Error message
Bad write method arg count: ${writeMethod} What it means
IntrospectionException from PropertyDescriptorUtils.findPropertyType when the write method's parameter count is not exactly 1. JavaBean setters take exactly one argument (the new value); 0, 2, or more args make the method not a valid setter and the property type cannot be determined.
Source
Thrown at spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java:166
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)) {
// Proceed with read method's property type
}
else {
throw new IntrospectionException(
"Type mismatch between read and write methods: " + readMethod + " - " + writeMethod);
}
}
else {
propertyType = params[0];
}
}View on GitHub (pinned to e8729d0438)
Solutions
- Make the simple setter take exactly one parameter.
- If it is an indexed setter, register it via IndexedPropertyDescriptor.setIndexedWriteMethod (2 params: int, value).
- Rename the method so it is not mistaken for a setter.
Example fix
// before
public void setItems(int index, String value) { ... } // registered as simple writeMethod
// after
new IndexedPropertyDescriptor("items", readMethod, writeMethod,
indexedReadMethod, MyClass.class.getDeclaredMethod("setItems", int.class, String.class)); Defensive patterns
Strategy: validation
Validate before calling
static void assertValidWriteMethod(Method writeMethod) {
if (writeMethod.getParameterCount() != 1) {
throw new IllegalArgumentException(
"Simple write method must take exactly 1 param: " + writeMethod);
}
} Type guard
static boolean isValidSimpleWriteMethod(Method m) {
return m != null && m.getParameterCount() == 1;
} Try / catch
try {
return new PropertyDescriptor(name, readMethod, writeMethod);
} catch (java.beans.IntrospectionException ex) {
if (ex.getMessage().startsWith("Bad write method arg count")) {
// promote to indexed if 2-arg, else bail
if (writeMethod.getParameterCount() == 2) {
return new IndexedPropertyDescriptor(name, null, null, null, writeMethod);
}
}
throw ex;
} Prevention
- Simple setters take exactly one parameter.
- Use IndexedPropertyDescriptor for 2-arg (int, value) setters.
- Rename non-setter methods that begin with 'set'.
When it happens
Trigger: Passing a method with 0 or 2+ parameters as writeMethod to PropertyDescriptor construction (non-indexed). Often a setFoo() with no params or setFoo(a, b) registered as a simple rather than indexed setter.
Common situations: Overloaded setFoo(...) methods; generated setters that take extra context parameters; confusion between indexed setter (2 params: index, value) and simple setter (1 param).
Related errors
- Write method must have exactly 1 or 2 parameters: ${method}
- Bad read method arg count: ${readMethod}
- Read method returns void: ${readMethod}
- 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/c4c7b4c6bb1d5a3b.json.
Report an issue: GitHub.