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

modal dialog will hang if created within synchronized method

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 1.1.5
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:

      Description



      Name: rk38400 Date: 04/11/98


      Creation of a modal dialog box will hang up
      if the call is within a synchronized block. The
      dialog box may or not get painted, but the whole
      system will quickly become unresponsive, and no
      further window repainting will be done.

      I will attach source below which demonstrates the
      problem.

      This bug is probably related to #4034834, which
      was posted over a year ago.

      This badly needs to be fixed, or at least properly
      documented.

      Thanks,
      --Mike



      import com.sun.java.swing.*;
      import java.awt.event.*;
      import java.io.*;

      public class DialogBug extends JFrame {
        public DialogBug() {
          JButton goodButton = new JButton("This works");
          goodButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) { good(); }
          });

          JButton badButton = new JButton("But this hangs");
          badButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) { bad(); }
          });

          getContentPane().add(goodButton, "West");
          getContentPane().add(badButton, "East");
          pack();
        }

        public void good() {
          JOptionPane.showMessageDialog(null, "We're cool!", "Modal Dialog",
      JOptionPane.INFORMATION_MESSAGE);
          synchronized (this) {
            notify();
          }
        }

        public synchronized void bad() {
          JOptionPane.showMessageDialog(null, "We're hosed!", "Modal Dialog",
      JOptionPane.ERROR_MESSAGE);
          notify();
        }

        public synchronized void showAndWait() throws InterruptedException {
          show();
          wait();
        }

        public static void main(String[] args) {
          DialogBug db = new DialogBug();
          try {
            db.showAndWait();
          } catch (InterruptedException e) {
          }
        }
      }
      (Review ID: 26253)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                amfowler Anne Fowler (Inactive)
                Reporter:
                rkarsunw Ralph Kar (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: