{"id":"07b6d5e2f91253eb","repo":"spring-projects/spring-framework","slug":"bad-indexed-read-method-arg-count-indexedreadme","errorCode":null,"errorMessage":"Bad indexed read method arg count: ${indexedReadMethod}","messagePattern":"Bad indexed read method arg count: (.+?)","errorType":"exception","errorClass":"IntrospectionException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java","lineNumber":200,"sourceCode":"\t\t\t\tpropertyType = params[0];\n\t\t\t}\n\t\t}\n\n\t\treturn propertyType;\n\t}\n\n\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}","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java#L182-L218","documentation":"IntrospectionException from PropertyDescriptorUtils.findIndexedPropertyType when an indexed read method does not take exactly 1 parameter. Indexed getters must take exactly one argument (the int index); any other arity is invalid for an indexed accessor.","triggerScenarios":"Registering a method as indexedReadMethod whose parameter count is 0 or >=2; e.g. getItems() (no index) or getItems(int, int) passed to an IndexedPropertyDescriptor.","commonSituations":"Confusion between simple getter (0 params) and indexed getter (1 param); overloaded indexed accessors; tooling misclassifying methods.","solutions":["Ensure the indexed read method takes exactly one parameter (the int index).","If the method is a simple getter, register it as readMethod (non-indexed), not indexedReadMethod.","Rename overloaded variants to remove the ambiguity."],"exampleFix":"// before\nnew IndexedPropertyDescriptor(\"items\", null, null,\n    MyClass.class.getDeclaredMethod(\"getItems\"), null);  // 0 args\n\n// after\nnew IndexedPropertyDescriptor(\"items\", null, null,\n    MyClass.class.getDeclaredMethod(\"getItems\", int.class), null);","handlingStrategy":"validation","validationCode":"static void assertValidIndexedReadMethod(Method m) {\n    if (m.getParameterCount() != 1) {\n        throw new IllegalArgumentException(\"Indexed read method must take 1 param: \" + m);\n    }\n}","typeGuard":"static boolean isValidIndexedReadMethod(Method m) {\n    return m != null && m.getParameterCount() == 1;\n}","tryCatchPattern":"try {\n    return new IndexedPropertyDescriptor(name, null, null, indexedReadMethod, indexedWriteMethod);\n} catch (java.beans.IntrospectionException ex) {\n    if (ex.getMessage().startsWith(\"Bad indexed read method arg count\")) {\n        // re-resolve to the 1-arg variant\n        indexedReadMethod = Arrays.stream(clazz.getMethods())\n            .filter(x -> x.getName().equals(indexedReadMethod.getName()) && x.getParameterCount() == 1)\n            .findFirst().orElseThrow();\n    }\n    throw ex;\n}","preventionTips":["Indexed getters take exactly one parameter (the int index).","Do not register a 0-arg simple getter as indexedReadMethod.","Validate method shape programmatically before descriptor construction."],"tags":["property-descriptor","indexed","introspection","spring-beans"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}