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

modal dialog will hang if created within synchronized method

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.1.5
    • client-libs



      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)
      ======================================================================

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: