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

java.beans.VetoableChangeSupport c-tor(source) works wrong with null source

XMLWordPrintable

    • 1.2beta2
    • sparc
    • solaris_2.5
    • Verified



      Name: dsC58869 Date: 09/03/97



      java.beans.VetoableChangeSupport constructor() works wrong if called with null parameter.
      It creates an object with invalid state:
      firePropertyChange() call causes IllegalArgumentException

      This constructor shoud probably throw an IllegalArgumentException
      (as java.util.EventObject does) or a NullPointerException.

      java.beans.PropertyChangeSupport has the same problem.

      ==== Here is the test demonstrating the bug ====

      import java.beans.*;

      public class TestVCS {
        
        public static void main (String args[]) {
              System.out.println("passing a null source");
              NewVetoableChangeSupport changes = new NewVetoableChangeSupport(null);
      ChangeHandler alpha = new ChangeHandler();

              System.out.println("adding a listener");
      changes.addVetoableChangeListener(alpha);

              System.out.println("trying to fire an event");
      alpha.clear();
      try {
      changes.fireVetoableChange("fred", "foo","bah");
      } catch (PropertyVetoException pve) {
      pve.printStackTrace();
      }
      alpha.checkEvent(changes);

      System.out.println("passed");
              
        }

      }

      class NewVetoableChangeSupport extends VetoableChangeSupport {
        public NewVetoableChangeSupport(java.lang.Object source) {
          super(source);
        }
      }

      class ChangeHandler implements VetoableChangeListener {

          private PropertyChangeEvent lastEvent;

          public void vetoableChange(PropertyChangeEvent evt) {
      lastEvent = evt;
          }

          public void checkEvent(Object source) {
              if (lastEvent==null || source!=lastEvent.getSource()) {
      System.out.println("failed: wrong event");
      System.exit(1);
      }
          }

          public void checkNoEvent() {
              if (lastEvent!=null) {
      System.out.println("failed: no event expected");
      System.exit(2);
      }
          }

          public void clear() {
      lastEvent = null;
          }
      }

      ==== Here is the output of the test ====

      %java TestVCS
      passing a null source
      adding a listener
      trying to fire an event
      java.lang.IllegalArgumentException: null source
      at java.util.EventObject.<init>(EventObject.java:30)
      at java.beans.PropertyChangeEvent.<init>(PropertyChangeEvent.java:54)
      at java.beans.VetoableChangeSupport.fireVetoableChange(VetoableChangeSupport.java:143)
      at TestVCS.main(TestVCS.java:16)

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

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

            ghamiltosunw Graham Hamilton (Inactive)
            dsilaev Dmitri Silaev
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: