Getter mismatch causing ClassCastException during entity merge


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( ~[cuba-global-7.2.17.jar:7.2.17]
	at com.haulmont.chile.core.model.impl.AbstractInstance.setValue( ~[cuba-global-7.2.17.jar:7.2.17]
	at com.haulmont.cuba.core.entity.BaseGenericIdEntity.setValue( ~[cuba-global-7.2.17.jar:7.2.17]
	at com.haulmont.cuba.gui.model.impl.DataContextImpl.setPropertyValue( ~[cuba-gui-7.2.17.jar:7.2.17]
	at com.haulmont.cuba.gui.model.impl.DataContextImpl.setPropertyValue( ~[cuba-gui-7.2.17.jar:7.2.17]
	at com.haulmont.cuba.gui.model.impl.DataContextImpl.mergeState( ~[cuba-gui-7.2.17.jar:7.2.17]
	at com.haulmont.cuba.gui.model.impl.DataContextImpl.internalMerge( ~[cuba-gui-7.2.17.jar:7.2.17]
	at com.haulmont.cuba.gui.model.impl.DataContextImpl.merge( ~[cuba-gui-7.2.17.jar:7.2.17]
	at com.haulmont.cuba.gui.model.impl.InstanceLoaderImpl.load( ~[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.


Hi @michael.renaud

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