United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-8008366 [macosx] ActionListener called twice for JMenuItem using ScreenMenuBar
JDK-8008366 : [macosx] ActionListener called twice for JMenuItem using ScreenMenuBar

Details
Type:
Bug
Submit Date:
2013-02-18
Status:
Resolved
Updated Date:
2013-05-14
Project Name:
JDK
Resolved Date:
2013-04-22
Component:
client-libs
OS:
os_x
Sub-Component:
javax.swing
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
7u40
Fixed Versions:

Related Reports
Backport:
Duplicate:

Sub Tasks

Description
test/javax/swing/JMenuItem/ActionListenerCalledTwice/ActionListenerCalledTwiceTest.java test fails if the keystroke is changed to KeyEvent.VK_DELETE and called twice. See attached modified version of ActionListenerCalledTwiceTest for details.
                                    

Comments
Test case.
                                     
2013-02-18
The test fails because the following code in CMenuItem.m does not work correctly:

    NSEvent *currEvent = [[NSApplication sharedApplication] currentEvent];
    if ([currEvent type] == NSKeyDown) {
        NSString *menuKey = [sender keyEquivalent];
        NSString *eventKey = [currEvent charactersIgnoringModifiers];
        if ([menuKey isEqualToString:eventKey]) {
            return;
        }
    }

'menuKey' is not equal to 'eventKey' in case of KeyEvent.VK_DELETE. menuKey is NSDeleteCharacter, but eventKey is NSDeleteFunctionKey. So the following naive patch fixes the test:

diff -r c1304eb051f6 src/macosx/native/sun/awt/CMenuItem.m
--- a/src/macosx/native/sun/awt/CMenuItem.m	Thu Feb 14 11:44:09 2013 -0800
+++ b/src/macosx/native/sun/awt/CMenuItem.m	Mon Feb 18 09:36:44 2013 +0100
@@ -277,7 +277,7 @@
         case java_awt_event_KeyEvent_VK_TAB             : macKey = NSTabCharacter; break;
         case java_awt_event_KeyEvent_VK_ENTER           : macKey = NSCarriageReturnCharacter; break;
         case java_awt_event_KeyEvent_VK_BACK_SPACE      : macKey = NSBackspaceCharacter; break;
-        case java_awt_event_KeyEvent_VK_DELETE          : macKey = NSDeleteCharacter; break;
+        case java_awt_event_KeyEvent_VK_DELETE          : macKey = NSDeleteFunctionKey; break;
         case java_awt_event_KeyEvent_VK_CLEAR           : macKey = NSClearDisplayFunctionKey; break;
         case java_awt_event_KeyEvent_VK_AMPERSAND       : macKey = '&'; break;
         case java_awt_event_KeyEvent_VK_ASTERISK        : macKey = '*'; break;

Unfortunately keyEquivalent for NSDeleteFunctionKey is empty when displayed in NSMenuItem. So this simple fix cannot be used and NSDeleteFunctionKey would probably need some special treatment, like converting it to NSDeleteCharacter in handleAction: method.

                                     
2013-02-18
Note that above test works fine with JDK 6u38.
                                     
2013-02-18
Please provide "Introduced In Release" information. Is it from 7u4?
                                     
2013-02-19
Test fails for JDK 7u4 too.
                                     
2013-02-26
URL:   http://hg.openjdk.java.net/jdk8/awt/jdk/rev/578fb8766200
User:  leonidr
Date:  2013-04-22 15:27:27 +0000

                                     
2013-04-22
URL:   http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/578fb8766200
User:  lana
Date:  2013-05-07 18:40:01 +0000

                                     
2013-05-07



Hardware and Software, Engineered to Work Together