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

Constructor of java.beans.PropertyChangeEvent should declare thrown NPE for null source

XMLWordPrintable

    • b17
    • generic
    • generic
    • Verified

      The following constructor:
      http://download.oracle.com/javase/7/docs/api/java/beans/PropertyChangeEvent.html#PropertyChangeEvent%28java.lang.Object,%20java.lang.String,%20java.lang.Object,%20java.lang.Object%29

      Does not specify thrown NullPointerException for passed null source object
      However the parent constructor which is used by the implementation specifies:

      http://download.oracle.com/javase/7/docs/api/java/util/EventObject.html#EventObject%28java.lang.Object%29

      The following code illustrates this issue:

      import java.beans.PropertyChangeEvent;

      /**
       *
       */
      public class PropChangeEvent {

          public static void main(String[] args) {

              /**
               * Constructs a new PropertyChangeEvent.
                  Parameters:
                  source - The bean that fired the event.
                  propertyName - The programmatic name of the property that was changed.
                  oldValue - The old value of the property.
                  newValue - The new value of the property.
               */
              new PropertyChangeEvent(null, null, null, null);
          }

      }

      The output will be:

      Exception in thread "main" java.lang.IllegalArgumentException: null source
      at java.util.EventObject.<init>(EventObject.java:56)
      at java.beans.PropertyChangeEvent.<init>(PropertyChangeEvent.java:60)
      at bugs.PropChangeEvent.main(PropChangeEvent.java:20)

            malenkov Sergey Malenkov (Inactive)
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: