spring-projects/spring-framework · error · IntrospectionException
Bad write method arg count
Error message
Bad write method arg count: {writeMethod} What it means
Thrown as java.beans.IntrospectionException by PropertyDescriptorUtils.findPropertyType when the supplied write method does not have exactly one parameter. JavaBeans simple setters must take exactly one argument.
Solutions
- Make the setter take exactly one parameter of the property type.
- Rename non-conforming set-prefixed methods to avoid being treated as setters.
- Use indexed setter convention (setXxx(int, value)) only if the property is truly indexed - but note this method only validates simple setters.
Example fix
// before
public void setAge(int age, String unit) { ... }
// after
public void setAge(int age) { ... } Defensive patterns
Strategy: validation
Validate before calling
if (writeMethod != null && writeMethod.getParameterCount() != 1) {
throw new IllegalArgumentException("setter must take 1 arg: " + writeMethod);
} Type guard
static boolean validSimpleSetter(Method m) {
return m != null && m.getParameterCount() == 1;
} Prevention
- Simple setters take exactly one argument.
- Rename multi-arg 'set' methods that are not true setters.
- Use builder/withXxx naming for fluent APIs.
When it happens
Trigger: findPropertyType(readMethod, writeMethod) is called and writeMethod.getParameterTypes().length != 1 - e.g. a setter with 0, 2, or 3+ parameters.
Common situations: A setXxx method with no args or with extra args (overloaded setters, fluent setters), a method wrongly named with the 'set' prefix, or generated classes producing non-conformant setters.
Related errors
- Bad indexed read method arg count
- Bad indexed write method arg count
- Bad read method arg count
- Indexed read method returns void
- Non int index to indexed read method
AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09).
Data as JSON: /api/errors/1bf6def57f666a3d.
Report an issue: GitHub.
Appendix: 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 69bf83ad71)