Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4092905

java.beans.PropertyChangeSupport is incorrectly serialized.

XMLWordPrintable

    • 1.2fcs
    • sparc
    • solaris_2.5
    • Verified



      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
      ---------------------

      ======================================================================

            ghamiltosunw Graham Hamilton (Inactive)
            ovlasov Oleksandr Vlasov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: