The code below is a small example that easily reproduces the issue. So I have variable of type String, on which a default value is set. I have 3 methods:
- getter
- setter
- convenience method that converts the string to boolean
The introspection does not return the getter as the readMethod and the setter as the writeMethod. Instead it returns the isTest() method as the readMethod. The setter is empty.
From the documentation I understand that if the type would be a boolean, the "is" method has higher precedence over get, but the type is String, so it does not make sense to even look for an "is-xxx" method?
public class Test {
public class Arguments {
private String test = Boolean.toString(true);
public boolean isTest() {
return Boolean.parseBoolean(test);
}
public String getTest() {
return test;
}
public void setTest(String test) {
this.test = test;
}
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IntrospectionException {
BeanInfo info = Introspector.getBeanInfo(Arguments.class);
System.out.println("Getter: " + info.getPropertyDescriptors()[1].getReadMethod());
System.out.println("Setter: " + info.getPropertyDescriptors()[1].getWriteMethod());
PropertyDescriptor descr = new PropertyDescriptor("test", Arguments.class);
System.out.println("T");
}
}
Is there anyone who has some insight on this?
Additional information:
- The order does not change the outcome. The isTest() method is always seen as readMethod
- In case I simply rename the isTest() to bsTest(), it selects the getter and setter as readMethod and writeMethod. So it has something to do with "is-xxx".