JDK-4799266 : REGRESSION: JComboBox doesn't work in JPopupMenu
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.1
  • Priority: P3
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2003-01-06
  • Updated: 2003-12-19
  • Resolved: 2003-12-19
Description

Name: rmT116609			Date: 01/06/2003


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

FULL OPERATING SYSTEM VERSION : Microsoft Windows 2000 [Version 5.00.2195]


A DESCRIPTION OF THE PROBLEM :
Add a JComboBox into a popup menu and attach the popup menu to a frame. Click the frame so that the popup menu show up with the combobox. At this time, if you click the combobox, exceptions occur.

I found this bug in the latest Java 1.4.1_01 JRE also. But 1.3.1 seems OK.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.NullPointerException
        at javax.swing.plaf.basic.BasicPopupMenuUI$MouseGrabber.grabContainer
(BasicPopupMenuUI.java:344)
        at javax.swing.plaf.basic.BasicPopupMenuUI$MouseGrabber.requestAddGrab
(BasicPopupMenuUI.java:227)
        at javax.swing.plaf.basic.BasicPopupMenuUI$MouseGrabber.stateChanged
(BasicPopupMenuUI.java:273)
        at javax.swing.MenuSelectionManager.fireStateChanged
(MenuSelectionManager.java:158)
        at javax.swing.MenuSelectionManager.setSelectedPath
(MenuSelectionManager.java:86)
        at javax.swing.JPopupMenu.setVisible(JPopupMenu.java:741)
        at javax.swing.JPopupMenu.show(JPopupMenu.java:912)
        at javax.swing.plaf.basic.BasicComboPopup.show(BasicComboPopup.java:177)
        at javax.swing.plaf.basic.BasicComboPopup.togglePopup
(BasicComboPopup.java:982)
        at
javax.swing.plaf.basic.BasicComboPopup$InvocationMouseHandler.mousePressed
(BasicComboPopup.java:632)
        at java.awt.AWTEventMulticaster.mousePressed
(AWTEventMulticaster.java:218)
        at java.awt.Component.processMouseEvent(Component.java:5090)
        at java.awt.Component.processEvent(Component.java:4890)
        at java.awt.Container.processEvent(Container.java:1566)
        at java.awt.Component.dispatchEventImpl(Component.java:3598)
        at java.awt.Container.dispatchEventImpl(Container.java:1623)
        at java.awt.Component.dispatchEvent(Component.java:3439)
        at java.awt.LightweightDispatcher.retargetMouseEvent
(Container.java:3450)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3162)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
        at java.awt.Container.dispatchEventImpl(Container.java:1609)
        at java.awt.Window.dispatchEventImpl(Window.java:1585)
        at java.awt.Component.dispatchEvent(Component.java:3439)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy
(EventDispatchThread.java:197)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy
(EventDispatchThread.java:150)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Test
{
	public static void main(String[] args)
	{
		JFrame frame = new JFrame();

		frame.setSize(400, 400);
		frame.setVisible(true);

		String[] list = {"1", "2", "3", "4",};
		JComboBox comb = new JComboBox(list);
		final JPopupMenu pop = new JPopupMenu();
		pop.add(comb);

		frame.addMouseListener (new MouseAdapter() {
			public void mousePressed(MouseEvent e)
			{
				System.out.println("mousePressed");
					pop.show(e.getComponent(), e.getX(), e.getY());
			}

		});
	}
}
---------- END SOURCE ----------

Release Regression From : 1.3.1_06
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Review ID: 179650) 
======================================================================

Comments
EVALUATION Name: azR10139 Date: 01/14/2003 We are not cheking if invoker is not null before calling its methods. The idea of suggested fix is to check if invoker is null and not to perform container grabbing if so. ====================================================================== Name: apR10262 Date: 12/19/2003 This bug is not reproducible with JDK1.5.0b31 on Windows XP and Solaris ======================================================================
24-08-2004

SUGGESTED FIX Name: azR10139 Date: 01/14/2003 ------- BasicPopupMenuUI.java ------- *** /tmp/sccs.9EaayD Wed Jan 8 18:58:01 2003 --- BasicPopupMenuUI.java Wed Jan 8 18:57:39 2003 *************** *** 350,356 **** void grabContainer(Container c, Component excluded) { ! if(c == excluded) return; MenuSelectionManager msm = MenuSelectionManager.defaultManager(); --- 350,356 ---- void grabContainer(Container c, Component excluded) { ! if(c== null || c == excluded) return; MenuSelectionManager msm = MenuSelectionManager.defaultManager(); ======================================================================
24-08-2004