JDK-4834687 : JOptionPane hangs when repeatedly instantiated
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.4.1
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-03-19
  • Updated: 2003-03-24
  • Resolved: 2003-03-24
Related Reports
Duplicate :  
Description

Name: rmT116609			Date: 03/19/2003


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

FULL OS VERSION :
Microsoft Windows 2000 [Version 5.00.2195]

A DESCRIPTION OF THE PROBLEM :
JOptionPane hangs when instantiated multiple times quickly.
i.e. Open, make selection, Close, Open, make selection, Close....

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a frame with a button in it.
Add an action listener on the button that creates a JOptionPane asking for yes/no input (doesn't really matter).
Click on the button to popup the option pane.
Press space to close option pane( default button ).
Press space to open option pane ( now default button of form is selected ).
Repeat quickly.
  Bug shows itself best if you have some sort of cpu time consuming process between each optionPane instantiation.  This is simulated by a thread.wait in the example code.

EXPECTED VERSUS ACTUAL BEHAVIOR :
The option pane closes and opens fine.
JOption pane eventually hangs, not redrawing its contents.  And not allowing itself to be closed.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package OptionPaneBug;

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class Application
{
	Frame frame;

	//Construct the application
	public Application()
	{
		frame = new Frame();
		frame.setSize(100,100);

		JButton button = new JButton("Click me");
		frame.add( button );

		button.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				JOptionPane.showConfirmDialog(frame,"Hello");

				try
				{
					// simulate a fair amount of internal processing.
					Thread.sleep(200);
				}
				catch( Exception ex )
				{
					ex.printStackTrace();
				}
			}
		});

		frame.setVisible(true);
	}

	//Main method
	public static void main(String[] args)
	{
		new Application();
	}
}
---------- END SOURCE ----------
(Review ID: 182816) 
======================================================================

Comments
EVALUATION I have been able to reproduce this in 1.4.1 but not in 1.4.2 beta. To reproduce, I simply followed the submitter's instructions. When the application comes up, first hit the button to show the JOptionPane. Then rapidly hit the space bar. To reproduce even easier, change the sleep code to sleep for a longer period of time. I strongly suspect that this is an AWT bug, fixed in 1.4.2. Re-assigning to AWT to confirm/deny this. ###@###.### 2003-03-21 Name: osR10079 Date: 03/24/2003 This is one more duplicate of 4531693 (Deadlock while showing a modal dialog from inkoveAndWait()). In this case we have the following situation: during frame activation DefaultKeyboardFocusManager tries to redispatch key event from type-ahead queue (KEY_PRESSED for space). In handler for this event test shows option pane (modal dialog). And so we have the situation, described in 4531693: showing modal dialog from within Focus- or WindowEvent's handler. ###@###.### 2003-03-24 ======================================================================
24-03-2003