JDK-6893358 : StringIndexOutOfBoundsException: String index out of range: 0 when trying to show JFrame
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7
  • Priority: P2
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: generic
  • CPU: generic
  • Submitted: 2009-10-20
  • Updated: 2012-03-22
  • Resolved: 2009-11-13
Related Reports
Relates :  
Description
The following code below leads to throwing 
"java.lang.StringIndexOutOfBoundsException: String index out of range: 0"

JDK7 b70 - PASSES
JDK7 b73 - FAILS
JDK7 b74 - PASSES

Platforms: Windows, Solaris x86
--------------------------------------------------------------------------
import javax.swing.*;

public class JMenu2030 {

    public static void main(String[] args) throws Exception {
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override public void run() {
                JFrame frame = new JFrame();
                try {
                    JMenu c = new JMenu();
                    frame.setJMenuBar(new JMenuBar());
                    frame.getJMenuBar().add(c);
                    frame.setVisible(true);
                } finally {
                    frame.dispose();
                }
            }
        });
    }
}
--------------------------------------------------------------------------
Exception in thread "main" java.lang.reflect.InvocationTargetException
	at java.awt.EventQueue.invokeAndWait(EventQueue.java:1034)
	at javax.swing.SwingUtilities.invokeAndWait(SwingUtilities.java:1346)
	at jmenu.JMenu2030.main(JMenu2030.java:8)
	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:617)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:105)
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: 0
	at java.lang.String.charAt(String.java:694)
	at sun.swing.SwingUtilities2.getLeftSideBearing(SwingUtilities2.java:248)
	at sun.swing.MenuItemLayoutHelper.getLeftExtraWidth(MenuItemLayoutHelper.java:162)
	at sun.swing.MenuItemLayoutHelper.calcExtraWidths(MenuItemLayoutHelper.java:158)
	at sun.swing.MenuItemLayoutHelper.reset(MenuItemLayoutHelper.java:148)
	at sun.swing.MenuItemLayoutHelper.<init>(MenuItemLayoutHelper.java:107)
	at javax.swing.plaf.basic.BasicMenuItemUI.getPreferredMenuItemSize(BasicMenuItemUI.java:408)
	at javax.swing.plaf.basic.BasicMenuItemUI.getPreferredSize(BasicMenuItemUI.java:363)
	at javax.swing.JComponent.getPreferredSize(JComponent.java:1650)
	at javax.swing.BoxLayout.checkRequests(BoxLayout.java:483)
	at javax.swing.BoxLayout.preferredLayoutSize(BoxLayout.java:300)
	at javax.swing.plaf.basic.DefaultMenuLayout.preferredLayoutSize(DefaultMenuLayout.java:60)
	at java.awt.Container.preferredSize(Container.java:1644)
	at java.awt.Container.getPreferredSize(Container.java:1629)
	at javax.swing.JComponent.getPreferredSize(JComponent.java:1652)
	at javax.swing.JRootPane$RootLayout.layoutContainer(JRootPane.java:1001)
	at java.awt.Container.layout(Container.java:1465)
	at java.awt.Container.doLayout(Container.java:1454)
	at java.awt.Container.validateTree(Container.java:1552)
	at java.awt.Container.validateTree(Container.java:1558)
	at java.awt.Container.validate(Container.java:1524)
	at java.awt.Window.show(Window.java:947)
	at java.awt.Component.show(Component.java:1546)
	at java.awt.Component.setVisible(Component.java:1498)
	at java.awt.Window.setVisible(Window.java:928)
	at jmenu.JMenu2030$1.run(JMenu2030.java:15)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:225)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:616)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:286)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:201)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:191)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:186)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:178)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:139)

The following JCK tests fail:

api/javax_swing/JMenu/descriptions.html#set_is_getXXX[JMenu2030]
api/javax_swing/plaf/basic/BasicMenuItemUI/index.html#protected[BasicMenuItemUI0009]
api/javax_swing/plaf/basic/BasicMenuItemUI/index.html#public[BasicMenuItemUI0002]
api/javax_swing/plaf/basic/BasicMenuItemUI/index.html#public[BasicMenuItemUI0003]
api/javax_swing/plaf/basic/BasicMenuItemUI/index.html#public[BasicMenuItemUI0004]
api/javax_swing/plaf/basic/BasicMenuItemUI/index.html#protected[BasicMenuItemUI0009]
api/javax_swing/plaf/multi/MultiMenuItemUI/index.html#public[MultiMenuItemUI0006]
api/javax_swing/plaf/multi/MultiMenuItemUI/index.html#public[MultiMenuItemUI2007]
api/javax_swing/JTable/AccessibleJTable/AccessibleJTableCell/index.html#AccessibleComponent[AccessibleJTableCell0031]
api/javax_swing/plaf/multi/MultiMenuItemUI/index.html#public[MultiMenuItemUI0006]
api/javax_swing/plaf/multi/MultiMenuItemUI/index.html#public[MultiMenuItemUI2007]

Comments
EVALUATION This problem was fixed by #6883341
13-11-2009

EVALUATION What information exactly is needed? This bug is reproducible with concrete JDK build (73); this CR deserves some other hypothetical CR in "see also" section fix of which lead to regression. If there's no such CR known this bug might be closed as "Not Reproducible". It was filed for the record.
10-11-2009

EVALUATION If it failes on JDK7 b73 but passes on JDK7 b74, why did you file the bug? I checked that it passes on my latest JDK 7 need more information
10-11-2009