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

BasicPopupMenuUI$MouseGrabber.windowClosed throws ArrayIndexOutOfBoundsException

    Details

      Description

      Name: aaR10142 Date: 10/09/2003



      javax.swing.plaf.basic.BasicPopupMenuUI$MouseGrabber.windowClosed method
      throws ArrayIndexOutOfBoundsException, when windows with menus a concurrently
      closed and opened. See details and test examples bellow.


      BEA reported having some problems with the JCK test in the subject
      (specifically AccessibleJMenu0009). They believe that either the
      testcase or the Swing implementation is broken. The error only
      occurs when all the (non-excluded) testcases are run and not when
      just AccessibleJMenu0009 is run alone.

      Let me try to explain the situation as I see it.

      What happens is this (let T1 and T2 be different threads):

      T1 - 1) Some testcase creates a JFrame
      T1 - 2) The testcase runs
      T1 - 3) The JFrame is disposed, which causes a WINDOW_CLOSE event to
      be put on the AWTEventQueue
      T1 - 4) AccessibleJMenu0009 starts and creates a new JFrame
      T1 - 5) JMenus are added to the frame
      T2 - 1) The AWTEventQueue thread is allowed to run and dispatches the
      WINDOW_CLOSE event to BasicPopupMenuUI$MouseGrabber.windowClosed()
      T2 - 2) This calls cancelPopupMenu() which removes the selected path
      from the current window's menu.
      T1 - 6) AccessibleJMenu0009 calls addAccessibleSelection(i) but the
      selection has now been cleared and the test fails

      This is of course timing dependent and the AWTEventQueue has to run at
      a "bad" time for this to happen, which is why this does not happen
      with HotSpot out-of-the-box.

      What seems to be wrong here is that
      BasicPopupMenuUI$MouseGrabber.windowClosed() does not care about
      _which_ window was closed but will clear the selection path from the
      _current_ window, which of course interferes with the next testcase.

      Below is a somewhat rewritten AccessibleJMenu0009 which will cause
      this to happen sooner or later. This has been verified with Java
      HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)

      Please let me know if you can confirm this and remove the test from
      the JCK.

      ========== test ===================
      void myTest()
          {
              for(;;)
              {
                 JMenu o = new JMenu();
                 AccessibleSelection c =
                    o.getAccessibleContext().getAccessibleSelection();
                 JFrame f = new JFrame();

                 try {
                    JMenu test[] = new JMenu[5];

                    for (int i = 0; i < test.length; i++) {
                       test[i] = new JMenu();
                       o.add(test[i]);
                    }
                    f.setJMenuBar(new JMenuBar());
                    f.getJMenuBar().add(o);

                    for (int i = 0; i < 5; i++) {
                       c.addAccessibleSelection(i);
                    }
                 } catch(Exception ex) {
                    ex.printStackTrace();
                    System.exit(0);
                 } finally {
                    f.dispose();
                 }
              }
           }
      ================= output ===================


      java.lang.ArrayIndexOutOfBoundsException: 1
              at javax.swing.MenuSelectionManager.getSelectedPath(MenuSelectionManager.java:99)
              at javax.swing.plaf.basic.BasicPopupMenuUI$MenuKeyboardHelper.stateChanged(BasicPopupMenuUI.java:973)
              at javax.swing.MenuSelectionManager.fireStateChanged(MenuSelectionManager.java:161)
              at javax.swing.MenuSelectionManager.setSelectedPath(MenuSelectionManager.java:87)
              at javax.swing.MenuSelectionManager.clearSelectedPath(MenuSelectionManager.java:109)
              at javax.swing.plaf.basic.BasicPopupMenuUI$MouseGrabber.cancelPopupMenu(BasicPopupMenuUI.java:289)
              at javax.swing.plaf.basic.BasicPopupMenuUI$MouseGrabber.windowClosed(BasicPopupMenuUI.java:476)
              at java.awt.Window.processWindowEvent(Window.java:1124)
              at javax.swing.JFrame.processWindowEvent(JFrame.java:266)
              at java.awt.Window.processEvent(Window.java:1079)
              at java.awt.Component.dispatchEventImpl(Component.java:3615)
              at java.awt.Container.dispatchEventImpl(Container.java:1627)
              at java.awt.Window.dispatchEventImpl(Window.java:1606)
              at java.awt.Component.dispatchEvent(Component.java:3477)
              at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
              at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
              at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
              at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              alisunw Ali Ali (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: