United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6515786 PIT: Vista(Win LAF) Pressing ESC Key throws "java.lang.ClassCastException: javax.swing.JPopupMenu"
6515786 : PIT: Vista(Win LAF) Pressing ESC Key throws "java.lang.ClassCastException: javax.swing.JPopupMenu"

Details
Type:
Bug
Submit Date:
2007-01-22
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
client-libs
OS:
windows_vista
Sub-Component:
javax.swing
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
5.0u12
Fixed Versions:
7

Related Reports
Backport:
Relates:
Relates:

Sub Tasks

Description
Build Info:
java version "1.5.0-2007-01-18-141443.idk.5-0u12"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-2007-01-18-141443.
idk.5-0u12-Administrator_18_jan_2007_14_19)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)

OS Info: Windows Vista Ultimate 6000

On WindowsLAF, on Vista, when the second level PopupMenu displayed, Pressing ESC Key results in throwing this following exception, after that PopupMenu is not rendering properly at all. 

You can reproduce this for the Normal Menu too, but it's not consistent. 

Steps to reproduce:

- Run the attached test MenuTest.java 
- Right Click on the TextArea, will display the JPopupMenu
- Traverse through the SubMenu 1 -> SubMenu 2 -> SubMenu 3
- Now Press the ESC key to dispose the PopupMenu, results in the following exception

To reproduce this with Menu

- Run the attached MenuLAFDemo.java
- Change the LAF to Windows using the "LookAndFeel" Menu
- Now click on the "MultiLevelMenu"
- Traverse to "MultiLevelMenuItem" -> "SecondLevelMenuItem - 4"
- Keep it selected, don't traverse next to the next level
- Now press ESC Key, throws the same execption. 

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.JPopupMenu
        at com.sun.java.swing.plaf.windows.WindowsMenuUI$1.getState(WindowsMenuUI.java:56)
        at com.sun.java.swing.plaf.windows.WindowsIconFactory$VistaMenuItemCheckIconFactory$VistaMenuItemCheckIcon.getIcon(WindowsIconFactory.java:833)
        at com.sun.java.swing.plaf.windows.WindowsIconFactory$VistaMenuItemCheckIconFactory$VistaMenuItemCheckIcon.getIconWidth(WindowsIconFactory.java:735)
        at javax.swing.plaf.basic.BasicMenuItemUI.layoutMenuItem(BasicMenuItemUI.java:823)
        at javax.swing.plaf.basic.BasicMenuItemUI.paintMenuItem(BasicMenuItemUI.java:580)
        at javax.swing.plaf.basic.BasicMenuItemUI.paint(BasicMenuItemUI.java:514)
        at javax.swing.plaf.basic.BasicMenuItemUI.update(BasicMenuItemUI.java:510)
        at javax.swing.JComponent.paintComponent(JComponent.java:743)
        at javax.swing.JComponent.paint(JComponent.java:1006)
        at javax.swing.JComponent.paintChildren(JComponent.java:843)
        at javax.swing.JComponent.paint(JComponent.java:1015)
        at javax.swing.JComponent.paintWithOffscreenBuffer(JComponent.java:4972)
        at javax.swing.JComponent.paintDoubleBuffered(JComponent.java:4925)
        at javax.swing.JComponent._paintImmediately(JComponent.java:4868)
        at javax.swing.JComponent.paintImmediately(JComponent.java:4675)
        at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:451)
        at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:114)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:461) 
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

                                    

Comments
EVALUATION

5.0u12 backport for 6432667 [Vista: Menu dropdown differs while compare with naitve in vista laf.] has this bug fixed too
                                     
2007-01-23
EVALUATION

The code which throws exception was copy&pasted from the other method
(WindowsMenuUI.painBackground) where it was used only for the top
level menus. Top level menu parent is always JMenuBar thus that cast was safe.

In WindowsMenuUI.getState that cast is used for all JMenus top level
or not. That caused that exception for sub menu JMenu items when in
model.isRollover() state.

Most of the time sub menu JMenu items with mouse over them are in
(model.isArmed() || model.isSelected()) state but not in
model.isRollover() state thus this bug is rarely encountered.

Pressing ESC some how triggers sub menu JMenu item to be in  model.isRollover() state.

Note: While the same code is present in 6u1 and 7.0 I could not
reproduce this bug there. Thus I do not think it is a showstopper for
6u and 7.0. From the other hand the code is wrong and should be fixed
even if it did not cause any bugs yet.

suggested changed for WindowsMenuUI.java

*** /tmp/geta6167	Mon Jan 22 13:46:48 2007
--- WindowsMenuUI.java	Mon Jan 22 13:44:27 2007
***************
*** 44,50 ****
                  if (model.isArmed() || model.isSelected()) {
                      state = (menu.isEnabled()) ? State.PUSHED 
                              : State.DISABLEDPUSHED;
!                 } else if (model.isRollover()) {
                      /* 
                       * Only paint rollover if no other menu on menubar is 
                       * selected
--- 44,51 ----
                  if (model.isArmed() || model.isSelected()) {
                      state = (menu.isEnabled()) ? State.PUSHED 
                              : State.DISABLEDPUSHED;
!                 } else if (model.isRollover() 
!                            && ((JMenu) menu).isTopLevelMenu()) {
                      /* 
                       * Only paint rollover if no other menu on menubar is 
                       * selected
                                     
2007-01-22



Hardware and Software, Engineered to Work Together