spring-projects/spring-framework · error · IntrospectionException
Read method returns void: ${readMethod}
Error message
Read method returns void: ${readMethod} What it means
IntrospectionException from PropertyDescriptorUtils.findPropertyType when the read method's return type is void. A getter must return the property value; a void return means there is no property type, so descriptor construction is impossible.
Source
Thrown at spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java:159
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)) {
// Proceed with read method's property type
}
else {
throw new IntrospectionException(View on GitHub (pinned to e8729d0438)
Solutions
- Give the method a non-void return type matching the field it exposes.
- If the method is a command not an accessor, rename it (e.g. fetchFoo(), loadFoo()) so it isn't treated as a getter.
- Drop it from the PropertyDescriptor construction.
Example fix
// before
public void getItems() { /* no-op */ }
// after
public List<String> getItems() { return items; } Defensive patterns
Strategy: validation
Validate before calling
static void assertReadMethodReturnsValue(Method readMethod) {
if (readMethod.getReturnType() == void.class) {
throw new IllegalArgumentException("Read method must not return void: " + readMethod);
}
} Type guard
static boolean returnsValue(Method m) {
return m != null && m.getReturnType() != void.class;
} Try / catch
try {
return new PropertyDescriptor(name, readMethod, writeMethod);
} catch (java.beans.IntrospectionException ex) {
if (ex.getMessage().startsWith("Read method returns void")) {
log.error("Getter {} returns void; cannot be a property read method", readMethod);
}
throw ex;
} Prevention
- Keep getters returning the field type; never void.
- Rename command-style 'getX()' methods to loadX()/fetchX().
- Static analysis: flag any 'get*()' method returning void.
When it happens
Trigger: Registering a getFoo() method that returns void as the readMethod of a PropertyDescriptor; rare in normal code, usually a coding error or generated bytecode where 'get' is used as a verb without a return.
Common situations: Hand-written getFoo() void methods mistaken for accessors; generated stubs where the getter body was left empty and the return type is void; legacy code where 'get' is a command rather than an accessor.
Related errors
- Bad read method arg count: ${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/c7fd173eab493bed.json.
Report an issue: GitHub.