{"id":"b5af42df46318e94","repo":"spring-projects/spring-framework","slug":"bad-indexed-write-method-arg-count-indexedwrite","errorCode":null,"errorMessage":"Bad indexed write method arg count: ${indexedWriteMethod}","messagePattern":"Bad indexed write method arg count: (.+?)","errorType":"exception","errorClass":"IntrospectionException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java","lineNumber":214,"sourceCode":"\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\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tthrow new IntrospectionException(\"Type mismatch between indexed read and write methods: \" +\n\t\t\t\t\t\t\tindexedReadMethod + \" - \" + indexedWriteMethod);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java#L196-L232","documentation":"IntrospectionException from PropertyDescriptorUtils.findIndexedPropertyType when an indexed write method does not take exactly 2 parameters. Indexed setters must take (int index, <value-type> value); any other arity is invalid.","triggerScenarios":"Registering setItems(String) (1 arg, simple setter) or setItems(int, String, Object) (3 args) as indexedWriteMethod; or a setItems(int) single-arg variant mistaken for an indexed setter.","commonSituations":"Confusion between simple and indexed setters; overloaded set methods; generators producing non-standard setter arity.","solutions":["Ensure the indexed setter takes exactly two parameters: int index then the value.","If it is a simple setter, register it as writeMethod (non-indexed), not indexedWriteMethod.","Rename overloaded variants to avoid misclassification."],"exampleFix":"// before\nnew IndexedPropertyDescriptor(\"items\", null,\n    MyClass.class.getDeclaredMethod(\"setItems\", String.class), null, null);\n\n// after\nnew IndexedPropertyDescriptor(\"items\", null, null, null,\n    MyClass.class.getDeclaredMethod(\"setItems\", int.class, String.class));","handlingStrategy":"validation","validationCode":"static void assertValidIndexedWriteMethod(Method m) {\n    if (m.getParameterCount() != 2) {\n        throw new IllegalArgumentException(\"Indexed write must take 2 params: \" + m);\n    }\n}","typeGuard":"static boolean isValidIndexedWriteMethod(Method m) {\n    return m != null && m.getParameterCount() == 2;\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 write method arg count\")) {\n        if (indexedWriteMethod.getParameterCount() == 1) {\n            // it is a simple setter, not indexed\n            return new PropertyDescriptor(name, indexedReadMethod, indexedWriteMethod);\n        }\n    }\n    throw ex;\n}","preventionTips":["Indexed setters take exactly two parameters: int index, then value.","Do not register a 1-arg simple setter as indexedWriteMethod.","Programmatically validate arity before descriptor construction."],"tags":["property-descriptor","indexed","introspection","spring-beans"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}