Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6893358

StringIndexOutOfBoundsException: String index out of range: 0 when trying to show JFrame

    Details

      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]

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                dbessono Dmitry Bessonov
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: