-
Bug
-
Resolution: Unresolved
-
P5
-
1.3.1, 8, 17, 19
-
Cause Known
-
generic
-
generic
Name: jl125535 Date: 11/16/2001
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)
(Also verified for JDK 1.4 beta 3 on Solaris 8)
According to the Beans specification one may fire a propertyChangeEvent with a
property name of null to indicate that multiple properties have changed. If
one is using java.bean.PropertyChangeSupport to handle the
PropertyChangeListeners then listeners that are added for a specific property
will not get notified if the property name passed to firePropertyChange is
null, only those listeners that are listening for general property changes.
I believe the correct behavior would be that if firePropertyChange is called
with null as the property name then all listeners should be notified.
Here's a piece of code that exhibits the behavior:
package foo.bugs.jdk;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
/**
* Code to show bug in PropertyChangeSupport where a listener of a specific
* property doesn't get notified when a property change event is fired for
* multiple properties.
*/
public class PropertyChangeSupportBug {
static public void main(final String[] args) {
new PropertyChangeSupportBug();
}
public PropertyChangeSupportBug() {
final PropertyChangeSupport jdk = new PropertyChangeSupport(this);
jdk.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(final PropertyChangeEvent pce) {
System.out.println("jdk general: " + pce.getPropertyName() + " old: "
+ pce.getOldValue() + " new: " + pce.getNewValue());
}
});
jdk.addPropertyChangeListener("foo", new PropertyChangeListener() {
public void propertyChange(final PropertyChangeEvent pce) {
System.out.println("jdk foo: " + pce.getPropertyName() + " old: " +
pce.getOldValue() + " new: " + pce.getNewValue());
}
});
//The foo property changed from 1 to 2.
//Both listeners should be notified
jdk.firePropertyChange("foo", 1, 2);
System.out.println("should see general print and foo print above");
System.out.println();
//Some number of properties changed on the object, all listeners should
//be notified, however only the general listener gets notified. This is
//the bug, the foo listener is not notified.
jdk.firePropertyChange(null, null, null);
System.out.println("should see general print and foo print above");
System.out.println();
//The bar property changed from 1 to 2.
//Only the general listener should be notified because no one is
//listening for specific bar events
jdk.firePropertyChange("bar", 1, 2);
System.out.println("should see just general print above");
System.exit(0);
}
}
(Review ID: 135812)
======================================================================
java version "1.3.1"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)
(Also verified for JDK 1.4 beta 3 on Solaris 8)
According to the Beans specification one may fire a propertyChangeEvent with a
property name of null to indicate that multiple properties have changed. If
one is using java.bean.PropertyChangeSupport to handle the
PropertyChangeListeners then listeners that are added for a specific property
will not get notified if the property name passed to firePropertyChange is
null, only those listeners that are listening for general property changes.
I believe the correct behavior would be that if firePropertyChange is called
with null as the property name then all listeners should be notified.
Here's a piece of code that exhibits the behavior:
package foo.bugs.jdk;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
/**
* Code to show bug in PropertyChangeSupport where a listener of a specific
* property doesn't get notified when a property change event is fired for
* multiple properties.
*/
public class PropertyChangeSupportBug {
static public void main(final String[] args) {
new PropertyChangeSupportBug();
}
public PropertyChangeSupportBug() {
final PropertyChangeSupport jdk = new PropertyChangeSupport(this);
jdk.addPropertyChangeListener(new PropertyChangeListener() {
public void propertyChange(final PropertyChangeEvent pce) {
System.out.println("jdk general: " + pce.getPropertyName() + " old: "
+ pce.getOldValue() + " new: " + pce.getNewValue());
}
});
jdk.addPropertyChangeListener("foo", new PropertyChangeListener() {
public void propertyChange(final PropertyChangeEvent pce) {
System.out.println("jdk foo: " + pce.getPropertyName() + " old: " +
pce.getOldValue() + " new: " + pce.getNewValue());
}
});
//The foo property changed from 1 to 2.
//Both listeners should be notified
jdk.firePropertyChange("foo", 1, 2);
System.out.println("should see general print and foo print above");
System.out.println();
//Some number of properties changed on the object, all listeners should
//be notified, however only the general listener gets notified. This is
//the bug, the foo listener is not notified.
jdk.firePropertyChange(null, null, null);
System.out.println("should see general print and foo print above");
System.out.println();
//The bar property changed from 1 to 2.
//Only the general listener should be notified because no one is
//listening for specific bar events
jdk.firePropertyChange("bar", 1, 2);
System.out.println("should see just general print above");
System.exit(0);
}
}
(Review ID: 135812)
======================================================================
- relates to
-
JDK-6587164 PropertyChangeSupport do not detect null change
-
- Closed
-