JDK-6857888 : closed/javax/swing/JMenuItem/6458123/bug6458123.java fails with InvocationTargetException.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2009-07-07
  • Updated: 2011-01-19
  • Resolved: 2009-10-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 Other
7 b74Fixed OpenJDK6Fixed
Related Reports
Relates :  
Description
Bug Info
=========
closed/javax/swing/JMenuItem/6458123/bug6458123.java fails with InvocationTargetException while running for JDK7-b64 pit.The issues causes due to the worng left alignment.

It fails on all platforms like solaris,windows and linux.

JDK Info
========
java version "1.7.0-internal"
Java(TM) SE Runtime Environment (build 1.7.0-internal-administrator_2009_07_01_0
0_43-b00)
Java HotSpot(TM) Client VM (build 16.0-b04, mixed mode)

Exception details
=================
java.lang.reflect.InvocationTargetException
	at java.awt.EventQueue.invokeAndWait(EventQueue.java:1034)
	at javax.swing.SwingUtilities.invokeAndWait(SwingUtilities.java:1350)
	at bug6458123.main(bug6458123.java:53)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:623)
	at com.sun.javatest.regtest.MainWrapper$MainThread.run(MainWrapper.java:94)
	at java.lang.Thread.run(Thread.java:717)
Caused by: java.lang.RuntimeException: Wrong left alignmet: previous = 39, current = 37, textRect, java.awt.Rectangle[x=37,y=2,width=219,height=15]

Comments
EVALUATION The test has a problem as well. It uses getDeclaredField(BasicMenuItemUI.class, "acceleratorDelimiter") to get the value of the field. The trick is, SynthMenuItemUI and SynthMenuUI define their own 'acceleratorDelimiter' fields that shade the field from the superclass. Hence null is returned, and the test assumes strings like "Shiftnull2" as accelerators.
23-09-2009

SUGGESTED FIX --- old/src/share/classes/javax/swing/plaf/nimbus/skin.laf 2009-09-21 16:44:55.000000000 +0400 +++ new/src/share/classes/javax/swing/plaf/nimbus/skin.laf 2009-09-21 16:44:54.000000000 +0400 @@ -14824,7 +14824,9 @@ <background/> <cacheSettingsInherited>false</cacheSettingsInherited> <cacheMode>NO_CACHING</cacheMode> - <uiproperties/> + <uiproperties> + <uiProperty name="textIconGap" type="INT" value="5"/> + </uiproperties> </style> <backgroundStates> <state stateKeys="Disabled"> --- old/src/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java 2009-09-21 16:44:58.000000000 +0400 +++ new/src/share/classes/javax/swing/plaf/synth/SynthGraphicsUtils.java 2009-09-21 16:44:57.000000000 +0400 @@ -475,11 +475,11 @@ return result; } - static void applyInsets(Rectangle rect, Insets insets) { + static void applyInsets(Rectangle rect, Insets insets, boolean leftToRight) { if (insets != null) { - rect.x += insets.left; + rect.x += (leftToRight ? insets.left : insets.right); rect.y += insets.top; - rect.width -= (insets.right + rect.x); + rect.width -= (leftToRight ? insets.right : insets.left) + rect.x; rect.height -= (insets.bottom + rect.y); } } @@ -492,12 +492,12 @@ g.setFont(style.getFont(context)); Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight()); - applyInsets(viewRect, mi.getInsets()); + boolean leftToRight = SynthLookAndFeel.isLeftToRight(mi); + applyInsets(viewRect, mi.getInsets(), leftToRight); SynthMenuItemLayoutHelper lh = new SynthMenuItemLayoutHelper( - context, accContext, mi, checkIcon, - arrowIcon, viewRect, defaultTextIconGap, acceleratorDelimiter, - SynthLookAndFeel.isLeftToRight(mi), + context, accContext, mi, checkIcon, arrowIcon, viewRect, + defaultTextIconGap, acceleratorDelimiter, leftToRight, MenuItemLayoutHelper.useCheckAndArrow(mi), propertyPrefix); MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem();
21-09-2009

EVALUATION A number of problems here. First, Nimbus defines "MenuItem.textIconGap" but not "Menu.textIconGap", so submenus and regular items are layed out differently. Second, SynthGraphicsUtils.applyInsets() should reverse insets for right-to-left items. A patch that fixes both problems is in Suggested Fix. The test still fails with it :( However, menus look visually just ok, maybe a problem with the test itself.
21-09-2009