Why use "null" for old value?

Dear CUBA team,
I’m trying to use property change listener to track property value. But I found for dynamic attributes, the old value is replaced by “null”. It’s a little confusing, as there is no other way to find old value.

com.haulmont.cuba.core.entity.BaseGenericIdEntity#setValue


if (newValue == null) {
    if (categoryAttributeValue != null) {
        categoryAttributeValue.setValue(null);
        categoryAttributeValue.setDeleteTs(AppBeans.get(TimeSource.class).currentTimestamp());
        propertyChanged(property, oldValue, null);
    }
} else if (!ObjectUtils.equals(oldValue, newValue)) {
    if (categoryAttributeValue != null) {
        categoryAttributeValue.setValue(newValue);
        categoryAttributeValue.setDeleteTs(null);
    } else {
        Metadata metadata = AppBeans.get(Metadata.NAME);
        ReferenceToEntitySupport referenceToEntitySupport = AppBeans.get(ReferenceToEntitySupport.class);

        categoryAttributeValue = metadata.create(CategoryAttributeValue.class);
        categoryAttributeValue.setValue(newValue);
        categoryAttributeValue.setObjectEntityId(referenceToEntitySupport.getReferenceId(this));
        categoryAttributeValue.setCode(attributeCode);
        DynamicAttributes dynamicAttributesBean = AppBeans.get(DynamicAttributes.NAME);
        categoryAttributeValue.setCategoryAttribute(
                dynamicAttributesBean.getAttributeForMetaClass(getMetaClass(), attributeCode));
        dynamicAttributes.put(attributeCode, categoryAttributeValue);
    }
    propertyChanged(property, null, newValue);
}

Is this a defect?

Thanks for your time

1 Like

Hi Greg,

Yes, this is obviously a bug. We’ll fix it ASAP, see the linked issue.

Thank you for reporting!

Thanks for your explanation. I hope we can make it better and better

Hi,
The problem is fixed in the platform version 6.5.6.

:ticket: See the following issue in our bug tracker:

https://youtrack.cuba-platform.com/issue/PL-9394