{"record":{"id":"15839f8a858ed827","repo":"spring-projects/spring-framework","slug":"non-int-index-to-indexed-write-method","errorCode":null,"errorMessage":"Non int index to indexed write method: {}","messagePattern":"Non int index to indexed write method: (.+?)","errorType":"exception","errorClass":"IntrospectionException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java","lineNumber":217,"sourceCode":"\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 {\n\t\t\t\tindexedPropertyType = params[1];\n\t\t\t}\n\t\t}","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java#L199-L235","documentation":"Thrown by Spring's PropertyDescriptorUtils when introspecting a JavaBean indexed property whose indexed write method (setter) does not take an int as its first parameter. JavaBeans requires an indexed setter to have the signature setX(int index, Type value); any other first-argument type (long, Long, etc.) is rejected. Spring throws IntrospectionException (a checked exception from java.beans) so bean wiring aborts.","triggerScenarios":"Calling BeanWrapperImpl / CachedIntrospectionResults on a class that has a method matching the setX(int?, ...) indexed-setter naming convention but whose first parameter is not exactly int.class (e.g. setItem(long, String)). Triggered during getDeclaredMethods introspection in findIndexedPropertyType() at line 216.","commonSituations":"A developer names a helper method like setPosition(long index, Value) on a bean that is later injected/bound by Spring; or uses a wrapper type (Long) for the index thinking it is equivalent to int. Also surfaces after refactoring a collection indexed access where the index field type was widened to long.","solutions":["Change the indexed setter's first parameter to int: setX(int index, Type value).","If the method is not meant to be an indexed setter, rename it so it does not collide with the getX(int)/setX(int, ...) convention.","If you truly need a long index, do not expose it as a JavaBeans indexed property; provide a plain setter and handle indexing internally."],"exampleFix":"// before\npublic void setItem(long index, Item item) { this.items[(int) index] = item; }\n\n// after\npublic void setItem(int index, Item item) { this.items[index] = item; }","handlingStrategy":"validation","validationCode":"// Verify an indexed setter uses int before exposing the bean to Spring\nMethod m = beanClass.getDeclaredMethod(\"setItem\", long.class, Object.class);\nthrow new IllegalStateException(\"setItem must take int index, not long\");","typeGuard":"// Indexed setter shape guard for JavaBeans\nstatic boolean isValidIndexedSetter(Method m) {\n    Class<?>[] p = m.getParameterTypes();\n    return m.getName().startsWith(\"set\") && p.length == 2 && p[0] == int.class;\n}","tryCatchPattern":null,"preventionTips":["Keep indexed accessors to the strict JavaBeans signature: getX(int)/setX(int, T).","Run an IDE 'generate getters/setters' on array fields rather than hand-writing index methods.","Avoid non-int index types (long/Long) on any method named setX/getX."],"tags":["java-beans","introspection","indexed-property","beanwrapper"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}