Project

General

Profile

Actions

bug #7872

closed

use firePropertyChange only if the value has changed

Added by Andreas Kohlbecker over 5 years ago. Updated over 5 years ago.

Status:
Worksforme
Priority:
New
Category:
cdmlib
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Severity:
normal
Found in Version:

Description

this is an example from Team where a PropertyChangeEvent is fired even if this.nomenclaturalTitle.equals(nomenclaturalTitle) == true

Before firing the event an equality check should be done to prevent from sending events unnecessarily.

public void setNomenclaturalTitle(String nomenclaturalTitle, boolean protectedNomenclaturalTitleCache) {
        firePropertyChange("nomenclaturalTitle", this.nomenclaturalTitle, nomenclaturalTitle);
        this.nomenclaturalTitle = nomenclaturalTitle == "" ? null: nomenclaturalTitle;
        this.protectedNomenclaturalTitleCache = protectedNomenclaturalTitleCache;
    }
Actions #1

Updated by Andreas Müller over 5 years ago

  • Status changed from New to Resolved
  • Assignee changed from Andreas Müller to Andreas Kohlbecker
  • Target version changed from Unassigned CDM tickets to Release 5.5

If you follow the firePropertyChange call you come to PropertyChangeSupport

    public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
        if (oldValue == null || newValue == null || !oldValue.equals(newValue)) {
            firePropertyChange(new PropertyChangeEvent(this.source, propertyName, oldValue, newValue));
        }
    }

so the call is not further propagated and therefore not problematic.

I suggest to close with worksforme

Actions #2

Updated by Andreas Kohlbecker over 5 years ago

  • Status changed from Resolved to Worksforme
  • Target version deleted (Release 5.5)

great and agreed!

one hit before closing this as "worksforme", just in case you missed this out so far:

Since java 1.7 these awkward null save checks can elegantly be replaced by Objects.equals(), so

if (oldValue == null || newValue == null || !oldValue.equals(newValue)) {

can become

if (!Objects.equals(oldValue, newValue)) {
Actions #3

Updated by Andreas Müller over 5 years ago

Andreas Kohlbecker wrote:

great and agreed!

one hit before closing this as "worksforme", just in case you missed this out so far:

Since java 1.7 these awkward null save checks can elegantly be replaced by Objects.equals(), so

if (oldValue == null || newValue == null || !oldValue.equals(newValue)) {

can become

if (!Objects.equals(oldValue, newValue)) {

Ahh, didn't know this. I am always using CdmUtils.nullSafeEquals(o,o)

Actions

Also available in: Atom PDF