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

java.util.Observable.addObserver(Observer) does not throw NullPointerException.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.3.0
    • docs
    • beta
    • sparc
    • solaris_2.5



      Name: ksC84122 Date: 07/26/99


      java.util.Observable.addObserver(Observer)
      should throw NullPointerException if null parameter is passed.

      In JDK 1.3 addObserver(null) returns silently which causes
      notifyObservers() throwing an unexpected exception.

      Here is the example demonstrating the bug:
      --------------------Test.java------------------------
      import java.util.*;

      class MyObservable extends Observable {
          public void change() {
              super.setChanged();
          }
      }

      public class Test {
         public static void main(String args[]) {
              MyObservable obj = new MyObservable();
              try {
                  obj.addObserver(null);
              } catch(NullPointerException e) {
                  System.out.println("NullPointerException in addObserver(null)");
              }

              obj.change();

              try {
                  obj.notifyObservers(new Object());
      } catch(NullPointerException e) {
                  System.out.println("NullPointerException in notifyObservers()");
              }
          }
      }

      ------------- Output under JDK 1.2.2 -------------------------------------
      NullPointerException in notifyObservers()


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

            mmcclosksunw Michael Mccloskey (Inactive)
            skosunw Sko Sko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: