{"id":"4b36bcbbd798c927","repo":"spring-projects/spring-framework","slug":"indexed-read-method-returns-void-indexedreadmet","errorCode":null,"errorMessage":"Indexed read method returns void: ${indexedReadMethod}","messagePattern":"Indexed read method returns void: (.+?)","errorType":"exception","errorClass":"IntrospectionException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java","lineNumber":207,"sourceCode":"\t/**\n\t * See {@link java.beans.IndexedPropertyDescriptor#findIndexedPropertyType}.\n\t */\n\tpublic static @Nullable Class<?> findIndexedPropertyType(String name, @Nullable Class<?> propertyType,\n\t\t\t@Nullable Method indexedReadMethod, @Nullable Method indexedWriteMethod) throws IntrospectionException {\n\n\t\tClass<?> indexedPropertyType = null;\n\n\t\tif (indexedReadMethod != null) {\n\t\t\tClass<?>[] params = indexedReadMethod.getParameterTypes();\n\t\t\tif (params.length != 1) {\n\t\t\t\tthrow new IntrospectionException(\"Bad indexed read method arg count: \" + indexedReadMethod);\n\t\t\t}\n\t\t\tif (params[0] != int.class) {\n\t\t\t\tthrow new IntrospectionException(\"Non int index to indexed read method: \" + indexedReadMethod);\n\t\t\t}\n\t\t\tindexedPropertyType = indexedReadMethod.getReturnType();\n\t\t\tif (indexedPropertyType == void.class) {\n\t\t\t\tthrow new IntrospectionException(\"Indexed read method returns void: \" + indexedReadMethod);\n\t\t\t}\n\t\t}\n\n\t\tif (indexedWriteMethod != null) {\n\t\t\tClass<?>[] params = indexedWriteMethod.getParameterTypes();\n\t\t\tif (params.length != 2) {\n\t\t\t\tthrow new IntrospectionException(\"Bad indexed write method arg count: \" + indexedWriteMethod);\n\t\t\t}\n\t\t\tif (params[0] != int.class) {\n\t\t\t\tthrow new IntrospectionException(\"Non int index to indexed write method: \" + indexedWriteMethod);\n\t\t\t}\n\t\t\tif (indexedPropertyType != null) {\n\t\t\t\tif (indexedPropertyType.isAssignableFrom(params[1])) {\n\t\t\t\t\t// Write method's property type potentially more specific\n\t\t\t\t\tindexedPropertyType = params[1];\n\t\t\t\t}\n\t\t\t\telse if (params[1].isAssignableFrom(indexedPropertyType)) {\n\t\t\t\t\t// Proceed with read method's property type","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java#L189-L225","documentation":"IntrospectionException from PropertyDescriptorUtils.findIndexedPropertyType when an indexed read method returns void. An indexed getter must return the element type at the given index; void return provides no element type so the descriptor cannot be constructed.","triggerScenarios":"An indexed getX(int) method declared void, registered as indexedReadMethod; usually a stub or a method named 'get' that performs a side effect rather than returning an element.","commonSituations":"Legacy get(int) methods that remove and return nothing; generated stubs; methods named 'get' used as commands.","solutions":["Give the indexed getter a non-void return type matching the element type.","If the method is a command, rename it so it isn't treated as an accessor."],"exampleFix":"// before\npublic void getItems(int index) { /* evict */ }\n\n// after\npublic String getItems(int index) { return items[index]; }","handlingStrategy":"validation","validationCode":"static void assertIndexedReadReturnsValue(Method m) {\n    if (m.getReturnType() == void.class) {\n        throw new IllegalArgumentException(\"Indexed read must not return void: \" + m);\n    }\n}","typeGuard":"static boolean indexedReadReturnsValue(Method m) {\n    return m != null && m.getReturnType() != void.class;\n}","tryCatchPattern":"try {\n    return new IndexedPropertyDescriptor(name, null, null, indexedReadMethod, indexedWriteMethod);\n} catch (java.beans.IntrospectionException ex) {\n    if (ex.getMessage().startsWith(\"Indexed read method returns void\")) {\n        log.error(\"Indexed getter returns void - make it return the element type\");\n    }\n    throw ex;\n}","preventionTips":["Indexed getters must return the element type, never void.","Rename command-style get(int) methods that do not return.","Validate return types of indexed accessors in unit tests."],"tags":["property-descriptor","indexed","introspection","spring-beans"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}