{"id":"c4c7b4c6bb1d5a3b","repo":"spring-projects/spring-framework","slug":"bad-write-method-arg-count-writemethod","errorCode":null,"errorMessage":"Bad write method arg count: ${writeMethod}","messagePattern":"Bad write method arg count: (.+?)","errorType":"exception","errorClass":"IntrospectionException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java","lineNumber":166,"sourceCode":"\tpublic static @Nullable Class<?> findPropertyType(@Nullable Method readMethod, @Nullable Method writeMethod)\n\t\t\tthrows IntrospectionException {\n\n\t\tClass<?> propertyType = null;\n\n\t\tif (readMethod != null) {\n\t\t\tif (readMethod.getParameterCount() != 0) {\n\t\t\t\tthrow new IntrospectionException(\"Bad read method arg count: \" + readMethod);\n\t\t\t}\n\t\t\tpropertyType = readMethod.getReturnType();\n\t\t\tif (propertyType == void.class) {\n\t\t\t\tthrow new IntrospectionException(\"Read method returns void: \" + readMethod);\n\t\t\t}\n\t\t}\n\n\t\tif (writeMethod != null) {\n\t\t\tClass<?>[] params = writeMethod.getParameterTypes();\n\t\t\tif (params.length != 1) {\n\t\t\t\tthrow new IntrospectionException(\"Bad write method arg count: \" + writeMethod);\n\t\t\t}\n\t\t\tif (propertyType != null) {\n\t\t\t\tif (propertyType.isAssignableFrom(params[0])) {\n\t\t\t\t\t// Write method's property type potentially more specific\n\t\t\t\t\tpropertyType = params[0];\n\t\t\t\t}\n\t\t\t\telse if (params[0].isAssignableFrom(propertyType)) {\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(\n\t\t\t\t\t\t\t\"Type mismatch between read and write methods: \" + readMethod + \" - \" + writeMethod);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tpropertyType = params[0];\n\t\t\t}\n\t\t}","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java#L148-L184","documentation":"IntrospectionException from PropertyDescriptorUtils.findPropertyType when the write method's parameter count is not exactly 1. JavaBean setters take exactly one argument (the new value); 0, 2, or more args make the method not a valid setter and the property type cannot be determined.","triggerScenarios":"Passing a method with 0 or 2+ parameters as writeMethod to PropertyDescriptor construction (non-indexed). Often a setFoo() with no params or setFoo(a, b) registered as a simple rather than indexed setter.","commonSituations":"Overloaded setFoo(...) methods; generated setters that take extra context parameters; confusion between indexed setter (2 params: index, value) and simple setter (1 param).","solutions":["Make the simple setter take exactly one parameter.","If it is an indexed setter, register it via IndexedPropertyDescriptor.setIndexedWriteMethod (2 params: int, value).","Rename the method so it is not mistaken for a setter."],"exampleFix":"// before\npublic void setItems(int index, String value) { ... }  // registered as simple writeMethod\n\n// after\nnew IndexedPropertyDescriptor(\"items\", readMethod, writeMethod,\n    indexedReadMethod, MyClass.class.getDeclaredMethod(\"setItems\", int.class, String.class));","handlingStrategy":"validation","validationCode":"static void assertValidWriteMethod(Method writeMethod) {\n    if (writeMethod.getParameterCount() != 1) {\n        throw new IllegalArgumentException(\n            \"Simple write method must take exactly 1 param: \" + writeMethod);\n    }\n}","typeGuard":"static boolean isValidSimpleWriteMethod(Method m) {\n    return m != null && m.getParameterCount() == 1;\n}","tryCatchPattern":"try {\n    return new PropertyDescriptor(name, readMethod, writeMethod);\n} catch (java.beans.IntrospectionException ex) {\n    if (ex.getMessage().startsWith(\"Bad write method arg count\")) {\n        // promote to indexed if 2-arg, else bail\n        if (writeMethod.getParameterCount() == 2) {\n            return new IndexedPropertyDescriptor(name, null, null, null, writeMethod);\n        }\n    }\n    throw ex;\n}","preventionTips":["Simple setters take exactly one parameter.","Use IndexedPropertyDescriptor for 2-arg (int, value) setters.","Rename non-setter methods that begin with 'set'."],"tags":["property-descriptor","introspection","setter","spring-beans"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}