{"id":"c7fd173eab493bed","repo":"spring-projects/spring-framework","slug":"read-method-returns-void-readmethod","errorCode":null,"errorMessage":"Read method returns void: ${readMethod}","messagePattern":"Read method returns void: (.+?)","errorType":"exception","errorClass":"IntrospectionException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java","lineNumber":159,"sourceCode":"\t\ttarget.setBound(source.isBound());\n\t\ttarget.setConstrained(source.isConstrained());\n\t}\n\n\t/**\n\t * See {@link java.beans.PropertyDescriptor#findPropertyType}.\n\t */\n\tpublic static @Nullable Class<?> findPropertyType(@Nullable Method readMethod, @Nullable Method writeMethod)\n\t\t\tthrows IntrospectionException {\n\n\t\tClass<?> propertyType = null;\n\n\t\tif (readMethod != null) {\n\t\t\tif (readMethod.getParameterCount() != 0) {\n\t\t\t\tthrow new IntrospectionException(\"Bad read method arg count: \" + readMethod);\n\t\t\t}\n\t\t\tpropertyType = readMethod.getReturnType();\n\t\t\tif (propertyType == void.class) {\n\t\t\t\tthrow new IntrospectionException(\"Read method returns void: \" + readMethod);\n\t\t\t}\n\t\t}\n\n\t\tif (writeMethod != null) {\n\t\t\tClass<?>[] params = writeMethod.getParameterTypes();\n\t\t\tif (params.length != 1) {\n\t\t\t\tthrow new IntrospectionException(\"Bad write method arg count: \" + writeMethod);\n\t\t\t}\n\t\t\tif (propertyType != null) {\n\t\t\t\tif (propertyType.isAssignableFrom(params[0])) {\n\t\t\t\t\t// Write method's property type potentially more specific\n\t\t\t\t\tpropertyType = params[0];\n\t\t\t\t}\n\t\t\t\telse if (params[0].isAssignableFrom(propertyType)) {\n\t\t\t\t\t// Proceed with read method's property type\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrow new IntrospectionException(","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java#L141-L177","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\npublic void getItems() { /* no-op */ }\n\n// after\npublic List<String> getItems() { return items; }","handlingStrategy":"validation","validationCode":"static void assertReadMethodReturnsValue(Method readMethod) {\n    if (readMethod.getReturnType() == void.class) {\n        throw new IllegalArgumentException(\"Read method must not return void: \" + readMethod);\n    }\n}","typeGuard":"static boolean returnsValue(Method m) {\n    return m != null && m.getReturnType() != void.class;\n}","tryCatchPattern":"try {\n    return new PropertyDescriptor(name, readMethod, writeMethod);\n} catch (java.beans.IntrospectionException ex) {\n    if (ex.getMessage().startsWith(\"Read method returns void\")) {\n        log.error(\"Getter {} returns void; cannot be a property read method\", readMethod);\n    }\n    throw ex;\n}","preventionTips":["Keep getters returning the field type; never void.","Rename command-style 'getX()' methods to loadX()/fetchX().","Static analysis: flag any 'get*()' method returning void."],"tags":["property-descriptor","introspection","getter","spring-beans"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}