bug #7872
closeduse firePropertyChange only if the value has changed
0%
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;
}
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
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)) {
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)