JDK-4821653 : EventQueue.push() causes JOptionPane.showInternalMessageDialog() to hang
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-02-20
  • Updated: 2003-02-21
  • Resolved: 2003-02-21
Related Reports
Relates :  
Description

Name: jl125535			Date: 02/20/2003


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


FULL OPERATING SYSTEM VERSION : Bug is not OS-dependent.
It fails on all systems.


ADDITIONAL OPERATING SYSTEMS : Solaris/X86



EXTRA RELEVANT SYSTEM CONFIGURATION :
The bug has nothing to do with the OS. It occurs under
both Windows and Solaris.

A DESCRIPTION OF THE PROBLEM :
The method "Toolkit.getDefaultEventQueue()" fails to
return the most recent "pushed" event queue. As a result,
if there is a pending call to EventQueue.push(), then
any code that attempts to steal events from
the queue returned by "Toolkit.getDefaultEventQueue()"
will hang.

The method JOptionPane.showInternalMessageDialog(...)
is a case in point.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Execute the code below. You'll see an error message
on the console that shows Toolkit.getDefaultEventQueue
problem. If you then select the button in the
window that is displayed, the AWT will hang.



EXPECTED VERSUS ACTUAL BEHAVIOR :
I expect to be able to invoke
JOptionPane.showInternalMessageDialog()
without the AWT thread locking up.

This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
/**
 * This test demonstrates a bug  in which the EventQueue thread
 * hangs when an internal dialog is brought up.
 * Simply select the button in the display to see the bug
 * demonstrated.
 *
 * The bug is caused by "Toolkit.getSystemEventQueue().push(e)"  not correctly
 *  updating the value returned by subsequent calls to
"Toolkit.getSystemEventQueue()".
 * The method JInternalFrame.startModal() calls getNextEvent on
  Toolkit.getSystemEventQueue(),
 * which is not active. It then deadlocks.
 */
class T {
    public static void main(String args[]){
       final JFrame frame = new JFrame("Test");
       final JButton b = new JButton("test");
       final JDesktopPane desk = new JDesktopPane();
       frame.getContentPane().add(desk,BorderLayout.CENTER);
       JInternalFrame jf = new JInternalFrame("Test");
       desk.add(jf);
       jf.getContentPane().add(b);
       jf.pack();
       jf.show();

       EventQueue newE = new EventQueue();
       Toolkit.getDefaultToolkit().getSystemEventQueue().push(newE);
       if (Toolkit.getDefaultToolkit().getSystemEventQueue() != newE){
           System.err.println("Toolkit.getSystemEventQueue is not updated!");
           System.err.println("Any subsequent attempts to call \"getNextEvent\"
will hang.");
           System.err.println("This is precisely what
JOption.showInternalMessageDialog does!");
           }

       b.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent event){
               JOptionPane.showInternalMessageDialog(desk,"Test");
               }
           });
       frame.pack();
       frame.setSize(300,300);
       frame.show();
       }

---------- END SOURCE ----------

CUSTOMER WORKAROUND :
I came across this bug while I was attempting to implement
a "JInternalDialog" class (why isn't one provided?)

I'll have to resort to some means other than relying
on EventQueue.push().
(Review ID: 145087) 
======================================================================

Comments
EVALUATION We should check to see if this still exists in the latest build of Mantis (17). ###@###.### 2003-02-20 It has been suggested that this may be a duplicate of 4667544. ###@###.### 2003-02-20 This bug is no longer reproducible in build 16 of Mantis. We believe it was fixed by the putback for 4667544. ###@###.### 2003-02-21
20-02-2003