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

java.util.Observable.notifyObservers() doesn't conform to api

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 1.1.7
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description



      Name: dbT83986 Date: 02/17/99


      The java api states the notifyObservers() checks to see
      if hasChanged(), notifies the observers, and then calls
      clearChanged(). However, in reality, it constructs an
      array of Observers to notify, then calls clearChanged,
      then notifies the controllers.

      This is a codelet from java.util.notifyObservers():

         synchronized (this) {
      /* We don't want the Observer doing callbacks into
      * into arbitrary code while holding its own Monitor.
      * The code where we extract each Observable from
      * the Vector and store the state of the Observer
      * needs synchronization, but notifying observers
      * does not (should not). The worst result of any
      * potential race-condition here is that:
      * 1) a newly-added Observer will miss a
      * notification in progress
      * 2) a recently unregistered Observer will be
      * wrongly notified when it doesn't care
      */
      if (!hasChanged())
      return;
      size = obs.size();
      if (size > arr.length) {
      arr = new Observer[size];
      }
      obs.copyInto(arr);
      clearChanged();
      }

      for (int i = size -1; i>=0; i--) {
      if (arr[i] != null) {
      arr[i].update(this, arg);
      }
      }

      In my program, I needed to know exactly what changed so I have
      private variables to indicate what changed. Each observer
      checks these statuses if they are notified. I overrode
      clearChanged() to set these statuses back assuming that they
      would be cleared AFTER the controllers were actually notified
      and not before.

      public void clearChanged()
      {
      super.clearChanged();
      mSectorDisplayChanged = false;
      mAccountDisplayChanged = false;
      mGroupDisplayChanged = false;
      }
      (Review ID: 48263)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              smarks Stuart Marks
              Reporter:
              dblairsunw Dave Blair (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: