JDK-8139169 : [macosx] Action registered for keyboard shortcut is called twice
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8u60
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • CPU: x86
  • Submitted: 2015-10-05
  • Updated: 2016-01-07
  • Resolved: 2015-12-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9 b100Fixed
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)

ADDITIONAL OS VERSION INFORMATION :
OSX El Capitan v 10.11

A DESCRIPTION OF THE PROBLEM :
I have a swing action with an accelerator like "meta shift COMMA". I put it in the component's action map, when I invoke it, the action is called twice.

ADDITIONAL REGRESSION INFORMATION: 
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a swing action, set on it as accelerator "meta shift COMMA", add it in the input map of a component, trigger it and it will get called twice.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The action should only get called once.
ACTUAL -
The action gets triggered twice.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package ro.sync;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.KeyStroke;
import javax.swing.text.BadLocationException;

/**
 * @author mircea
 */
public class TestFrame {

  /**
   * @param args
   */
  public static void main(String[] args) {
    System.setProperty("com.apple.mrj.application.apple.menu.about.name", "A test frame");
    System.setProperty("apple.laf.useScreenMenuBar", "true");
    // This is in case of Java 1.3 on Mac OS X.
    System.setProperty("com.apple.macos.useScreenMenuBar", "true");
    
    JFrame frame = new JFrame("Test frame !");
    
    JPanel content = new JPanel(new BorderLayout());
    
    final JTextArea textArea = new JTextArea();
    content.add(new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER);
    
    JMenuBar menuBar = new JMenuBar();
    frame.setJMenuBar(menuBar);
    
    Action a = new AbstractAction("Insert some text...") {
      @Override
      public void actionPerformed(ActionEvent arg0) {
        try {
          textArea.getDocument().insertString(0, "Some text... ", null);
        } catch (BadLocationException e) {
          e.printStackTrace();
        }
      }
    };
    KeyStroke keyStroke = KeyStroke.getKeyStroke("meta shift COMMA");
    a.putValue(Action.ACCELERATOR_KEY, keyStroke);
    
    textArea.getInputMap().put(keyStroke, "myAction");
    
    textArea.getActionMap().put("myAction", a);
    JMenu menu = new JMenu("The Menu");
    
    JMenuItem mi = new JMenuItem(a);
    mi.setAccelerator((KeyStroke) a.getValue(Action.ACCELERATOR_KEY));
    menu.add(mi);
    menuBar.add(menu);
    
    frame.getContentPane().add(content);
    
    frame.setLocation(200, 100);
    frame.setSize(500, 500);
    
    frame.setVisible(true);
  }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Use another shortcut for the action. Not all shortcuts lead to this problem.


Comments
Objective C issue
30-11-2015

OSX El Capitan v 10.11 is not a supported platform for JDK9 https://bugs.openjdk.java.net/browse/JDK-8130942
09-11-2015

Moving to JDK 9. Has a test case. Setting Fix/Version to JDK 9 for Dev evaluation. Will consider N-bp as needed.
08-10-2015