Why Java allows to fire property change when old and new values are null

Sergiy Medvynskyy :

The class PropertyChangeSupport fires the PropertyChangeEvent when both values (the old and the new) are null. Could somebody explain me what is the reason of this behavior? Some of my colleagues uses this behavior for event driven actions, but I think it's misuse of the property change pattern. Am I right or I misunderstand something?

I mean this line of code:

propertyChangeSupport.firePropertyChange(XY_PROPERTY, null, null);
mickle_ak :

I think, it is philosophical question – null is not a “normal” value, null means “unknown”, and “unknown” can’t be compared with another “unknown”, so if you change the property value from “unknown” to “unknown”, it is a NEW “unknown” value. So similar is it in database - NULL is always unequal to NULL.

From Bean Specification: "Null values may be provided for the old and the new values if their true values are not known.”

Another reason in Bean Specification: “An event source may send a null object as the name to indicate that an arbitrary set of if its properties have changed. In this case the old and new values should also be null."

For more details you can see open jdk issue 4763463 from 2002: (https://bugs.openjdk.java.net/browse/JDK-4763463)

I think, it is not very comfortable for development, but it is so. We can’t change it :-(

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=128978&siteId=1