{"record":{"id":"1bf6def57f666a3d","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/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java#L148-L184","documentation":"Thrown as java.beans.IntrospectionException by PropertyDescriptorUtils.findPropertyType when the supplied write method does not have exactly one parameter. JavaBeans simple setters must take exactly one argument.","triggerScenarios":"findPropertyType(readMethod, writeMethod) is called and writeMethod.getParameterTypes().length != 1 - e.g. a setter with 0, 2, or 3+ parameters.","commonSituations":"A setXxx method with no args or with extra args (overloaded setters, fluent setters), a method wrongly named with the 'set' prefix, or generated classes producing non-conformant setters.","solutions":["Make the setter take exactly one parameter of the property type.","Rename non-conforming set-prefixed methods to avoid being treated as setters.","Use indexed setter convention (setXxx(int, value)) only if the property is truly indexed - but note this method only validates simple setters."],"exampleFix":"// before\npublic void setAge(int age, String unit) { ... }\n\n// after\npublic void setAge(int age) { ... }","handlingStrategy":"validation","validationCode":"if (writeMethod != null && writeMethod.getParameterCount() != 1) {\n    throw new IllegalArgumentException(\"setter must take 1 arg: \" + writeMethod);\n}","typeGuard":"static boolean validSimpleSetter(Method m) {\n    return m != null && m.getParameterCount() == 1;\n}","tryCatchPattern":null,"preventionTips":["Simple setters take exactly one argument.","Rename multi-arg 'set' methods that are not true setters.","Use builder/withXxx naming for fluent APIs."],"tags":["property-descriptor","introspection","javabeans","spring-beans"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}