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

java.beans.VetoableChangeSupport is incorrectly serialized.

XMLWordPrintable

    • 1.2fcs
    • sparc
    • solaris_2.5
    • Verified



      Name: avC70361 Date: 11/14/97



        If an instance of java.beans.VetoableChangeSupport, which has been added an
      instance of VetoableChangeListener for a property name, has been serialized
      into a stream and deserialized back the java.beans.VetoableChangeSupport.
      hasListeners(String) method for that instance with the property name as the
      parameter throws NullPointerException.

      Here is the test demonstrating the bug:
      ------VetoableChangeSupportTest.java----------
      import java.beans.*;
      import java.io.*;

      public class VetoableChangeSupportTest {

        public static void main(String args[]) {

          ObjectOutputStream ostream = null;
          ObjectInputStream istream = null;
          VetoableChangeSupport support = new VetoableChangeSupport(new String());
          support.addVetoableChangeListener(
            "prop",
            new VetoableChangeListener() {
              public void vetoableChange(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)
            );

            ((VetoableChangeSupport)istream.readObject()).hasListeners("prop");

          } catch(Exception e) {
            System.out.println("Exception raised : " + e);
          }
        }

      }

      ---------------------
      Test output
      ---------------------
      #>java VetoableChangeSupportTest
      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: