{"id":"17359472ba3edecd","repo":"spring-projects/spring-framework","slug":"bad-read-method-arg-count-readmethod","errorCode":null,"errorMessage":"Bad read method arg count: ${readMethod}","messagePattern":"Bad read method arg count: (.+?)","errorType":"exception","errorClass":"IntrospectionException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java","lineNumber":155,"sourceCode":"\t\t}\n\n\t\t// See java.beans.PropertyDescriptor#PropertyDescriptor(PropertyDescriptor)\n\t\ttarget.setPropertyEditorClass(source.getPropertyEditorClass());\n\t\ttarget.setBound(source.isBound());\n\t\ttarget.setConstrained(source.isConstrained());\n\t}\n\n\t/**\n\t * See {@link java.beans.PropertyDescriptor#findPropertyType}.\n\t */\n\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)) {","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/e8729d043887bf0d0baf91e062e909b56eb2b708/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java#L137-L173","documentation":"IntrospectionException thrown by PropertyDescriptorUtils.findPropertyType when a candidate read method takes any parameters. The JavaBean contract requires read methods (getters) to have zero parameters; a getter with parameters is not a valid property accessor and PropertyDescriptor construction cannot proceed.","triggerScenarios":"Building a PropertyDescriptor where the supplied readMethod has parameterCount != 0; happens during introspection when a getFoo(...) method is mistakenly treated as the read method for property 'foo', or when hand-constructing PropertyDescriptors.","commonSituations":"A class with a getFoo(int index) method intended as an indexed getter but registered as a non-indexed read method; overloaded getFoo() vs getFoo(arg); tooling that auto-derives descriptors from method names without arity checks.","solutions":["If the method is an indexed accessor, register it as indexedReadMethod on an IndexedPropertyDescriptor (it then takes one int param).","Remove the parameter from the getter, or rename the parameterized method so it is not mistaken for the property's read method.","When building descriptors programmatically, pass a zero-arg method as readMethod."],"exampleFix":"// before\nnew PropertyDescriptor(\"items\", MyClass.class.getDeclaredMethod(\"getItems\", int.class), null);\n\n// after\nnew IndexedPropertyDescriptor(\"items\", null, null,\n    MyClass.class.getDeclaredMethod(\"getItems\", int.class), null);","handlingStrategy":"validation","validationCode":"// Validate a read method before constructing a descriptor\nstatic void assertValidReadMethod(Method readMethod) {\n    if (readMethod.getParameterCount() != 0) {\n        throw new IllegalArgumentException(\n            \"Read method must take 0 params: \" + readMethod);\n    }\n}","typeGuard":"static boolean isValidReadMethod(Method m) {\n    return m != null && m.getParameterCount() == 0 && m.getReturnType() != void.class;\n}","tryCatchPattern":"try {\n    return new PropertyDescriptor(name, readMethod, writeMethod);\n} catch (java.beans.IntrospectionException ex) {\n    if (ex.getMessage().startsWith(\"Bad read method arg count\")) {\n        // re-resolve to the zero-arg variant\n        readMethod = Arrays.stream(clazz.getMethods())\n            .filter(x -> x.getName().equals(readMethod.getName()) && x.getParameterCount() == 0)\n            .findFirst().orElseThrow();\n        return new PropertyDescriptor(name, readMethod, writeMethod);\n    }\n    throw ex;\n}","preventionTips":["Ensure getters take zero parameters.","If indexed, register via IndexedPropertyDescriptor.","Validate Method arity before constructing descriptors programmatically."],"tags":["property-descriptor","introspection","getter","spring-beans"],"analyzedSha":"e8729d043887bf0d0baf91e062e909b56eb2b708","analyzedAt":"2026-08-04T19:07:39.725Z","schemaVersion":2}