Name: avC70361 Date: 11/14/97
If an instance of java.beans.PropertyChangeSupport, which has been added an
instance of PropertyChangeListener for a property name, has been serialized
into a stream and deserialized back the java.beans.PropertyChangeSupport.
hasListeners(String) method for that instance with the property name as the
parameter throws NullPointerException.
Here is the test demonstrating the bug:
------PropertyChangeSupportTest.java----------
import java.beans.*;
import java.io.*;
public class PropertyChangeSupportTest {
public static void main(String args[]) {
ObjectOutputStream ostream = null;
ObjectInputStream istream = null;
PropertyChangeSupport support = new PropertyChangeSupport(new String());
support.addPropertyChangeListener(
"prop",
new PropertyChangeListener() {
public void propertyChange(PropertyChangeEvent evt) {
}
}
);
support.hasListeners("prop");
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ostream = new ObjectOutputStream(baos);
ostream.writeObject(support);
ostream.flush();
byte[] array = baos.toByteArray();
baos.close();
istream = new ObjectInputStream(
new ByteArrayInputStream(array)
);
((PropertyChangeSupport)istream.readObject()).hasListeners("prop");
} catch(Exception e) {
System.out.println("Exception raised : " + e);
}
}
}
---------------------
Test output
---------------------
#>java PropertyChangeSupportTest
Exception raised : java.lang.NullPointerException
---------------------
======================================================================