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

BasicMenuUI$MenuKeyHandler.menuKeyPressed() incorrect for dynamic menus.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 1.4.1
    • Fix Version/s: 1.4.2
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      mantis
    • CPU:
      sparc
    • OS:
      solaris_8
    • Verification:
      Verified

      Description

      Class javax.swing.plaf.basic.BasicMenuUI$MenuKeyHandler contains method menuKeyPressed(MenuKeyEvent). This method uses a mechanism that remembers last used mnenonics and indexes of JMenuItems that use this mnemonics. These indexes are used when the mnemonics is used again (it is used for cycling between items with the same mnemonics).
      But, this mechanism does not work correctly for dynamic size (dynamic item count) menus. The indexes are not invalidated after adding/removing a JMenuItem.
      When using the same mnemonics after adding/removing an item, the old index cache is used. This may cause incorrect index is used. This may cause incorrect item is selected, or even ArrayIndexOutOfBoundsException may occur.

      I have created a simple test application. To run it execute: "java -cp examples.jar examples.MenuTest". Please try following steps:
      1. Start the app.
      2. Open the menu, and press 'F'. The note will be written on stderr.
      3. Now, press "add" button. (New item is added into the menu.)
      4. Open the menu, press 'F'. The newly added item is executed, insted of correct "First item".
      5. Open the menu, press 'S'. This will clear the item-index cache, and execute "Second item".
      6. Press "Remove" button. (Removes item added in step 3).
      7. Open the menu, press 'S'. ArrayIndexOutOfBoundException will araise.

      These problems occurs on:
      bash-2.03$ java -version
      java version "1.4.1-rc"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-rc-b18)
      Java HotSpot(TM) Client VM (build 1.4.1-rc-b18, mixed mode)

      These problems does not occur on:
      bash-2.03$ /space/lahvac/JDK/j2sdk1.4.0/bin/java -version
      java version "1.4.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
      Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)


      ###@###.### 2002-11-26

      I have verified this bug on j2sdk1.4.2-build08 (mantis) by the attached test case.

        Attachments

          Activity

            People

            • Assignee:
              mdavidsosunw Mark Davidson (Inactive)
              Reporter:
              jlahoda Jan Lahoda
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: