JDK-8020591 : [macosx] Functional keys greater than F20 don't work as a menu shortcut
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7u40
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: os_x
  • Submitted: 2013-07-16
  • Updated: 2016-02-04
  • Resolved: 2014-03-13
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
This is a build of the next workspace
http://hg.openjdk.java.net/jdk7u/jdk7u40

+ webrev for 8019265 has been applied

denis@/export/wsps/jdk7u40>hg summary
parent: 703:a1ae13479e87 tip
Added tag jdk7u40-b33 for changeset 3fdfe7f1b063

openjdk version  " 1.7.0-internal " 
OpenJDK Runtime Environment (build 1.7.0-internal-denis_2013_07_12_14_24-b00)
OpenJDK 64-Bit Server VM (build 24.0-b52, 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 :
Despite the fact that the fix for 8019265 works brilliant , it still does not covers some cases.

REGRESSION.  Last worked in version 6u45

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the attached source code.
2. Use Up/Down arrows keys. You should notice that ItemEvents and ActionEvents are received.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
We do not press F24 and arrow key is not an accelerator, so we should not receive any notifications.
ACTUAL -
We are notified in ActionListener and ItemListener.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

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 " );
        JCheckBoxMenuItem firstMenuItem = new JCheckBoxMenuItem( " FirstItem " );

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

        KeyStroke ctrlShiftUp = KeyStroke.getKeyStroke( " shift meta DOWN " );

        firstMenuItem.setAccelerator(ctrlShiftUp);

        firstMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F24,0));

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

        firstMenuItem.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                System.err.println(e);
            }
        });
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                new SimpleEditor();

            }
        });
    }
}

---------- END SOURCE ----------
Comments
This issue has very little to do with JDK-8019265. My guess, although I have no proof at the moment, that this is a bug in OS X. I've played with your test and keys F1 through F20 works fine, Cocoa even draws a textual representation of the key in the menu item. It is F21 key from which the problem starts. And you've got no textual representation for it. The fact that there is no textual representation for keys > F21 makes me think that Carbon menu code can't handle functional keys above F20. So, when we set F24 key as a shortcut, which is actually two operations on the corresponding MenuItem (setKeyEquivalent: and setKeyEquivalentModifierMask: ), Carbon rejects F24 as a key equivalent, but accepts 0 (no mask) as a key equivalent modifier mask. As a result, we end up with a "key down" as a shortcut. This is my current hypothesis. I'll investigate it more, but this bug is a rather low priority for me, so as a workaround, in the Java code, call setAccelerator(null) before setting an actual accelerator.
16-07-2013