{"record":{"id":"4cda32fbd9cafb2d","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/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java#L141-L177","documentation":"Thrown as java.beans.IntrospectionException by PropertyDescriptorUtils.findPropertyType when the supplied read method's return type is void. A JavaBeans getter must return a value; a void return makes the property type unresolvable.","triggerScenarios":"findPropertyType(readMethod, writeMethod) is called and readMethod.getReturnType() == void.class. Means a void method was registered as a read method.","commonSituations":"A method named getXxx or isXxx that returns void (a typo, or a side-effecting 'is' method), a code generator that emitted getters incorrectly, or accidental registration of a non-getter void method as a property read method.","solutions":["Change the getter to return the property type instead of void.","Rename the void method so it is not picked up as a getter (no getXxx/isXxx prefix).","Regenerate the class with corrected getter signatures."],"exampleFix":"// before\npublic void getName() { return this.name; } // void return\n\n// after\npublic String getName() { return this.name; }","handlingStrategy":"validation","validationCode":"if (readMethod != null && readMethod.getReturnType() == void.class) {\n    throw new IllegalArgumentException(\"getter returns void: \" + readMethod);\n}","typeGuard":"static boolean getterReturnsValue(Method m) {\n    return m != null && m.getParameterCount() == 0 && m.getReturnType() != void.class;\n}","tryCatchPattern":null,"preventionTips":["Getters (getXxx/isXxx) must return a value, never void.","If a method only performs a side effect, do not name it with a getter prefix.","Code-review generated classes for void getters."],"tags":["property-descriptor","introspection","javabeans","spring-beans"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}