Getter mismatch causing ClassCastException during entity merge

Hi,

Given an entity Account with 2 fields debit and credit and their standard getters getDebit() and getCredit().

    @Money(currencyField = "currency")
    @MetaProperty(datatype = "bdMoney")
    @Column(name = "DEBIT")
    private BigDecimal debit;

    @Money(currencyField = "currency")
    @MetaProperty(datatype = "bdMoney")
    @Column(name = "CREDIT")
    private BigDecimal credit;

With 2 additional methods

    public boolean isDebit() {
        return nn(getDebit()).doubleValue() > 0;
    }

    public boolean isCredit() {
        return nn(getCredit()).doubleValue() > 0;
    }

When loading and merging entities, the following happens randomly

Caused by: java.lang.ClassCastException: class java.lang.Boolean cannot be cast to class java.math.BigDecimal (java.lang.Boolean and java.math.BigDecimal are in module java.base of loader 'bootstrap')
	at com.haulmont.chile.core.model.utils.MethodsCache$SettersHolder.accept(MethodsCache.java:193) ~[cuba-global-7.2.17.jar:7.2.17]
	at com.haulmont.chile.core.model.impl.AbstractInstance.setValue(AbstractInstance.java:160) ~[cuba-global-7.2.17.jar:7.2.17]
	at com.haulmont.cuba.core.entity.BaseGenericIdEntity.setValue(BaseGenericIdEntity.java:126) ~[cuba-global-7.2.17.jar:7.2.17]
	at com.haulmont.cuba.gui.model.impl.DataContextImpl.setPropertyValue(DataContextImpl.java:335) ~[cuba-gui-7.2.17.jar:7.2.17]
	at com.haulmont.cuba.gui.model.impl.DataContextImpl.setPropertyValue(DataContextImpl.java:330) ~[cuba-gui-7.2.17.jar:7.2.17]
	at com.haulmont.cuba.gui.model.impl.DataContextImpl.mergeState(DataContextImpl.java:274) ~[cuba-gui-7.2.17.jar:7.2.17]
	at com.haulmont.cuba.gui.model.impl.DataContextImpl.internalMerge(DataContextImpl.java:217) ~[cuba-gui-7.2.17.jar:7.2.17]
	at com.haulmont.cuba.gui.model.impl.DataContextImpl.merge(DataContextImpl.java:162) ~[cuba-gui-7.2.17.jar:7.2.17]
	at com.haulmont.cuba.gui.model.impl.InstanceLoaderImpl.load(InstanceLoaderImpl.java:112) ~[cuba-gui-7.2.17.jar:7.2.17]

The cause is that the getter that has been registered in the MethodsCache used during merge is “isDebit” instead of “getDebit”, even if 1) the return type (boolean) does not match the type of the property (BigDecimal), and even if 2) the “isDebit” method is not a @MetaProperty.

I know that “isXXX” is part of JavaBean getter spec as being name of a getter (for a boolean). But 1) and 2) could be checked while building the MethodsCache. Or if more simple, a hint in the IDE on the “isDebit” method notifying that this naming is not recommended and proposing a rename.

In my case “hasDebit” did the trick.

Regards
Michael

Hi @michael.renaud

Thank you for reporting the problem. We have created the Github issue.

Regards,
Nadezhda.