{"record":{"id":"3dd5f849bba1daa9","repo":"spring-projects/spring-framework","slug":"bad-indexed-write-method-arg-count","errorCode":null,"errorMessage":"Bad indexed write method arg count: {}","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/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java#L196-L232","documentation":"Thrown as java.beans.IntrospectionException by PropertyDescriptorUtils.findIndexedPropertyType when an indexed write method does not have exactly two parameters. Indexed setters must take exactly (int index, value) - i.e. two parameters with the first being the int index.","triggerScenarios":"findIndexedPropertyType called with an indexedWriteMethod whose parameter count != 2 (e.g. 1, 3, or 0 params).","commonSituations":"A setXxx method with wrong arity being treated as an indexed setter, a simple setter misregistered as indexed, or generated code emitting malformed indexed setters.","solutions":["Make the indexed setter take exactly two parameters, the first being int: void setXxx(int i, Type value).","If the property is not indexed, register it as a simple setter (1 param) instead.","Correct or regenerate the offending class."],"exampleFix":"// before\npublic void setItem(Item value); // wrong arity for indexed setter\n\n// after\npublic void setItem(int i, Item value);","handlingStrategy":"validation","validationCode":"if (indexedWriteMethod != null && indexedWriteMethod.getParameterCount() != 2) {\n    throw new IllegalArgumentException(\"indexed setter must take 2 args: \" + indexedWriteMethod);\n}","typeGuard":"static boolean validIndexedWriteMethod(Method m) {\n    return m != null && m.getParameterCount() == 2 && m.getParameterTypes()[0] == int.class;\n}","tryCatchPattern":null,"preventionTips":["Indexed setters take exactly two parameters: setXxx(int i, Type value).","Do not register simple single-arg setters as indexed.","Keep indexed and simple setter naming/arity distinct."],"tags":["property-descriptor","introspection","indexed-property","javabeans","spring-beans"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}