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

JDialog.setVisible fails to notify waiting thread

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P1 P1
    • 1.1.5
    • 1.1.4, 1.1.5
    • client-libs
    • 1.1.5
    • generic, unknown
    • solaris_2.5.1, windows_nt
    • Not verified



      From: Ray Tomlinson <###@###.###>
      To: ###@###.###
      Cc: ###@###.###
      Subject: JDialog.setVisible fails to notify waiting thread
      Date: Fri, 14 Nov 1997 12:02:13 -0500

      The setVisible method of JDialog contains a race: super.setVisible is done
      after notifyAll with the result that a thread waiting in blockingShow may
      be activated, find that the dialog is still visible, and continue waiting.
      After this, the thread setting visibility false continues, the dialog
      becomes invisible and the blockingShow thread stays blocked -- forever.

      Below is the relevant bytecode:

      Method void setVisible(boolean)
         0 iload_1
         1 ifne 27
         4 aload_0
         5 invokevirtual #75 <Method boolean isVisible()>
         8 ifeq 27
        11 aload_0
        12 astore_2
        13 aload_2
        14 monitorenter
        15 aload_0
        16 invokevirtual #76 <Method void notifyAll()>
        19 aload_2
        20 monitorexit
        21 goto 27
        24 aload_2
        25 monitorexit
        26 athrow
        27 aload_0
        28 iload_1
        29 invokespecial #86 <Method void setVisible(boolean)>
        32 return

      The corresponding source (which Sun has failed to provide), but deduced
      from the bytecode is:

      public void setVisible(boolean newVisible)
      {
        if (!newVisible && isVisible()) {
          synchronized(this) {
            notifyAll();
          }
        }
        super.setVisible(newVisible);
      }

      The code should probably be:

      public void setVisible(boolean newVisible)
      {
        boolean doNotify = (!newVisible && isVisible());
        super.setVisible(newVisible);
        if (doNotify) {
          synchronized(this) {
            notifyAll();
          }
        }
      }

      Ray Tomlinson


      From: Scott Violet <sky@southampton>
      To: ###@###.###
      CC: swing-feedback@taller
      Subject: Re: JDialog.setVisible fails to notify waiting thread
      Date: Fri, 14 Nov 1997 11:09:09 -0800

      Hi,
         Thanks for the excellent diagnosis of the bug! You are correct,
      super.setVisible() is incorrectly being messaged after notifyAll() is
      messaged. We will change this for a future release.
      Thanks again,

      -Scott Violet (###@###.###)

            sswingtrsunw Swingtraq Swingtraq (Inactive)
            sswingtrsunw Swingtraq Swingtraq (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: