Search code examples
javareflectionintrospectionbeaninfo

Java.beans.Introspector.getBeanInfo() fails to assign writeMethods


I made a super simple example that doesn't make any sense.

public static void main(String [] args) throws IntrospectionException {
    BeanInfo info = Introspector.getBeanInfo(DemandBidType.class);
    int breakpoint = 0;
}

Here's my class:

public class DemandBidType {
    protected Boolean isDuplicateHour;
    protected Boolean test;

    public boolean isIsDuplicateHour() {
        return isDuplicateHour;
    }

    public void setIsDuplicateHour(Boolean isDuplicateHour) {
        this.isDuplicateHour = isDuplicateHour;
    }

    public Boolean getTest() {
        return test;
    }

    public void setTest(Boolean test) {
        this.test = test;
    }
}

And here is a screen shot showing the problem; the field I care about isn't being recognized as having a write method. I added another field 'test' and that one works fine... There was very little related to this on Google, and what was there was years old with older java versions. You can see in the bottom right that I'm using 1.7.51.

Debugging Screenshot(https://i.sstatic.net/DKC6e.png)


Solution

  • It turns out it's because the return type of the getter doesn't match the argument of the setter. (One's "Boolean" the other "boolean").