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

JOptionPane.showInternalXXXDialog is not disposed on interrupt.

    XMLWordPrintable

Details

    Description

      FULL PRODUCT VERSION :
      java version "1.5.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
      Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      Internal dialogs created by the JOptionPane remain open and waiting for user interaction after the event dispatch thread is interrupted. The event dispatch thread is no longer wait for input from the Internal dialogs

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the source code provided. Wait for the run method and main method to exit.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      When the run method exits, all dialogs should have never opened or closed without any user interaction.
      ACTUAL -
      Without any user interaction the run method will exit but three internal dialogs will remain open and waiting for user input. The three frame dialogs are closed or never opened.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;


      public class DialogTest implements Runnable {
        private static final String MESSAGE = "Wait until the run method exits.";
        private static final String INT_PREFIX = "Dialog closed via interruption=";
        private static final String INT_SUFFIX = " Value returned=";

        private volatile Thread edt;

        public DialogTest() {
        }

        public void run() {
          System.out.println("run enter");
          edt = Thread.currentThread();
          try {
            //frame setup, ignore.
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JDesktopPane desk = new JDesktopPane();
            frame.setContentPane(desk);
            frame.setSize(320,200);
            frame.setVisible(true);
            //end frame setup

            JOptionPane.showMessageDialog(desk, MESSAGE);
            System.out.println(INT_PREFIX + Thread.interrupted());
          
            JOptionPane.showInternalMessageDialog(desk, MESSAGE);
            System.out.println(INT_PREFIX + Thread.interrupted());
          
            String valueAnswer = null;
            valueAnswer = JOptionPane.showInputDialog(desk, MESSAGE);
            System.out.println(INT_PREFIX + Thread.interrupted() + INT_SUFFIX + valueAnswer);
          
            valueAnswer = JOptionPane.showInternalInputDialog(desk, MESSAGE);
            System.out.println(INT_PREFIX + Thread.interrupted() + INT_SUFFIX + valueAnswer);

            int buttonAnswer = 0;
            buttonAnswer = JOptionPane.showConfirmDialog(desk, MESSAGE);
            System.out.println(INT_PREFIX + Thread.interrupted() + INT_SUFFIX + buttonAnswer);
          
            buttonAnswer = JOptionPane.showInternalConfirmDialog(desk, MESSAGE);
            System.out.println(INT_PREFIX + Thread.interrupted() + INT_SUFFIX + buttonAnswer);
            
            //at this point all dialogs should be closed, all interruption
            System.out.println("run exit ");
          }
          finally {
            edt = null; //signal main to exit.
          }
        }

        public static void main(String[] args) throws Exception {
          System.out.println("main enter");
          DialogTest dialogtest = new DialogTest();
          SwingUtilities.invokeLater(dialogtest);

          do {
            Thread.sleep(2L * 1000L);
            final Thread t = dialogtest.edt;
            if(t != null) {
              t.interrupt();
            }
            else {
              break;
            }
          } while(true);
          System.out.println("main exit");
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Don't use the internal dialog methods or create custom dialogs.

      Attachments

        Activity

          People

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Imported:
              Indexed: