United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-8019265 [macosx] apple.laf.useScreenMenuBar regression comparing with jdk6
JDK-8019265 : [macosx] apple.laf.useScreenMenuBar regression comparing with jdk6

Details
Type:
Bug
Submit Date:
2013-06-27
Status:
Resolved
Updated Date:
2013-12-06
Project Name:
JDK
Resolved Date:
2013-07-08
Component:
client-libs
OS:
os_x
Sub-Component:
java.awt
CPU:
Priority:
P3
Resolution:
Fixed
Affected Versions:
7u6
Fixed Versions:

Related Reports
Backport:
Backport:
Backport:
Relates:

Sub Tasks

Description
FULL PRODUCT VERSION :
This is a build of the next workspace
http://hg.openjdk.java.net/jdk7u/jdk7u40

denis@/export/wsps/jdk7u40>hg summary
parent: 691:11147a12bd8c tip
 Added tag jdk7u40-b30 for changeset 1c141e6fde91

java version  " 1.8.0-ea " 
Java(TM) SE Runtime Environment (build 1.8.0-ea-b93)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b34, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
OS X 10.8.4 (12E55)

EXTRA RELEVANT SYSTEM CONFIGURATION :
  Model Name:Mac mini
  Model Identifier:Macmini6,2
  Processor Name:Intel Core i7

A DESCRIPTION OF THE PROBLEM :
On Mac OS X a recommended way to set a system mac menu in java is using apple.laf.useScreenMenuBar property.

https://developer.apple.com/library/mac/#documentation/Java/Conceptual/Java14Development/07-NativePlatformIntegration/NativePlatformIntegration.html

The behaviour of the menu in jdk7 is different comparing with jdk6.

REGRESSION.  Last worked in version 6u45

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the next code with jdk7u40 and with jdk 6.

===================== SimpleEditor.java =================
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

class SimpleEditor extends JFrame {

    private final JTextArea textArea = new JTextArea(60, 30);

    private SimpleEditor() throws HeadlessException {
        super( " Simple editor " );

        System.setProperty( " apple.laf.useScreenMenuBar " ,  " true " );
        textArea.setText( " First
Second
PLACE CARET HERE
Fourth
Fifth " );
        textArea.setCaretPosition( " First
Second
PLACE " .length());
        add(textArea);
        JMenuBar mb = new JMenuBar();
        JMenu firstMenu = new JMenu( " FirstMenu " );
        JMenuItem menuItem = new JMenuItem( " FirstItem " );

        KeyStroke ctrlShiftUp = KeyStroke.getKeyStroke(KeyEvent.VK_UP,
                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()
                | InputEvent.SHIFT_MASK);

        menuItem.setAccelerator(ctrlShiftUp);

        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                System.err.println( " Action on menu item " );
            }
        });

        firstMenu.add(menuItem);

        mb.add(firstMenu);
        setJMenuBar(mb);
        pack();
        setVisible(true);
    }

    public static void main(String[] args) {

        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new SimpleEditor();

            }
        });
    }
}
====================================================

You can use Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() instead of InputEvent.META_MASK the behaviour is the same.

After the execution a frame with a JTextArea will be shown. The caret will be placed on the third line.

I have debugged the issue and found out that a message is send to the CMenuItem method by NSApplication. This leads to the extra call of the action.

0   liblwawt.dylib                      0x0000000118321f5e -[CMenuItem handleAction:] + 162
1   AppKit                              0x00007fff8a259959 -[NSApplication sendAction:to:from:] + 342
2   AppKit                              0x00007fff8a38f36c -[NSMenuItem _corePerformAction] + 406
3   AppKit                              0x00007fff8a38f05a -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 133
4   AppKit                              0x00007fff8a38dce0 -[NSMenu performKeyEquivalent:] + 271
5   AppKit                              0x00007fff8a38d1a3 -[NSApplication _handleKeyEquivalent:] + 829
6   AppKit                              0x00007fff8a24a143 -[NSApplication sendEvent:] + 4480
7   libosxapp.dylib                     0x00000001183aa64f -[NSApplicationAWT sendEvent:] + 179
8   AppKit                              0x00007fff8a16021a -[NSApplication run] + 636
9   libosxapp.dylib                     0x00000001183aa537 +[NSApplicationAWT runAWTLoopWithApp:] + 156
10  liblwawt.dylib                      0x0000000118301991 -[AWTStarter starter:] + 873
11  Foundation                          0x00007fff893f15ca __NSThreadPerformPerform + 225
12  CoreFoundation                      0x00007fff8900ab31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
13  CoreFoundation                      0x00007fff8900a455 __CFRunLoopDoSources0 + 245
14  CoreFoundation                      0x00007fff8902d7f5 __CFRunLoopRun + 789
15  CoreFoundation                      0x00007fff8902d0e2 CFRunLoopRunSpecific + 290
16  java                                0x00000001075f7390 CreateExecutionEnvironment + 871
17  java                                0x00000001075f1b3c JLI_Launch + 1952
18  java                                0x00000001075f76f4 main + 108
19  libdyld.dylib                       0x00007fff8d80a7e1 start + 0
20  ???                                 0x0000000000000006 0x0 + 6

It seems that the problem is not fixed by the next fixes.

changeset:   6072:e55e4808077a
user:        leonidr
date:        Tue May 14 21:04:32 2013 +0400
summary:     8008366: [macosx] ActionListener called twice for JMenuItem using ScreenMenuBar

changeset:   5337:33cc14b77bef
user:        leonidr
date:        Wed Sep 12 19:34:26 2012 +0400
summary:     7160951: ActionListener called twice for JMenuItem using ScreenMenuBar


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
1. Click on the  " FirstItem "  menu item.  " Action on menu item "  message will be printed in the error stream.
2. Press shortcut CMND+SHIFT+UP. Text will be selected from the initial caret position up to the first symbol in the textarea.
ACTUAL -
Additionally to the selection an  " Action on menu item "  message is printed

1. Click on the  " FirstItem "  menu item.  " Action on menu item "  message will be printed in the error stream.
2. Press shortcut CMND+SHIFT+UP. Text will be selected from the initial caret position up to the first symbol in the textarea.
3.  " Action on menu item "  message will be printed in the error stream.

REPRODUCIBILITY :
This bug can be reproduced always.
                                    

Comments
isn't a regression in Oracle's Java on Mac OS X
                                     
2013-06-28
URL:   http://hg.openjdk.java.net/jdk8/awt/jdk/rev/b7cbad879d63
User:  leonidr
Date:  2013-07-08 15:48:45 +0000

                                     
2013-07-08
why do we need to fix issue existing since fcs in 7u40 ATR b#4? Isn't it too late for it?
                                     
2013-07-08
Here are the reason why I'd like to see this fix in 7u40:
- People haven't complained about this issue before because of the low adoption rate of previous Java releases on OS X, not because it's unimportant
- 7u40 is a big milestone for Java on OS X. It brings a lot of fixes and enhancements. It would be pity to ship it with such stupid menu bug.
- It's OX only fix
- It's a low risk fix
                                     
2013-07-08
SQE OK to take this
                                     
2013-07-09
URL:   http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/b7cbad879d63
User:  lana
Date:  2013-07-23 18:11:27 +0000

                                     
2013-07-23
test/javax/swing/JMenuItem/ActionListenerCalledTwice/ActionListenerCalledTwiceTest.java has been modified to accommodate problematic keystrokes.
                                     
2013-09-06



Hardware and Software, Engineered to Work Together