JDK-8022997 : [macosx] Remaining duplicated key events
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7u6,7u40,8
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: os_x
  • Submitted: 2013-08-13
  • Updated: 2015-04-13
  • Resolved: 2013-08-14
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 7 JDK 8
7u60Fixed 8 b105Fixed
Description
FULL PRODUCT VERSION :
java version  " 1.7.0_40-ea " 
Java(TM) SE Runtime Environment (build 1.7.0_40-ea-b38)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b55, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
OSX 10.8.4

A DESCRIPTION OF THE PROBLEM :
I filed bug report 8020510, which was closed as NonReproducible because of fixes between 7u25 and 7u40.  I've updated and confirmed that cmd-delete and some other keystrokes are no longer duplicated in 7u40, but there are at least two keystrokes that are still duplicated when the JFrame is present (not duplicated when the JFrame is close.)

Cmd-Enter (or Meta-enter)
and Control-Enter

I have not combed through every possible key.  Since it seems like these are getting addressed piecemeal, that plus perhaps a unit test is justified:
first, http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8008366
second, http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8020510
and my report today shows there are still others.

REGRESSION.  Last worked in version 6u45

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
- System.setProperty(  "  apple.laf.useScreenMenuBar  "  ,   "  true  "  );
- Bind one of the listed keys as the accelerator to a menu action.
- Type the key into the application.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
A single event.

ACTUAL -
Two events.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.event.ActionEvent;

import javax.swing.*;

public class DemonstrateDuplicateKeys {
    public static void main(String[] args) {

      System.setProperty(  "  apple.laf.useScreenMenuBar  "  ,   "  true  "  );
      JFrame frame = new JFrame();
      JMenuBar jmb = new JMenuBar();
      jmb.removeAll();
      JMenu m = new JMenu(  "  Actions  "  );


      for (final String keyname : new String[] {  "  A  "  ,
                "  DELETE  "  ,   "  meta DELETE  "  ,   "  shift DELETE  "  ,   "  control DELETE  "  ,   "  alt DELETE  "  ,
                "  BACK_SPACE  "  ,   "  meta BACK_SPACE  "  ,   "  control BACK_SPACE  "  ,   "  shift BACK_SPACE  "  ,   "  alt BACK_SPACE  "  ,
                "  ENTER  "  ,   "  meta ENTER  "  ,   "  shift ENTER  "  ,   "  control ENTER  "  ,   "  alt ENTER  "  ,
                "  typed =  "  ,   "  meta typed =  "  ,   "  shift typed =  "  ,   "  control typed =  "  ,   "  alt typed =  "  ,
                "  typed b  "  ,   "  meta typed b  "  ,   "  shift typed b  "  ,   "  control typed b  "  ,   "  alt typed b  " 
              }) {
          addMenuItem(m, KeyStroke.getKeyStroke(keyname), quickieAction(keyname));
      }

      m.addSeparator();

      Action quitaction = new AbstractAction(  "  Quit  "  ) {
          @Override public void actionPerformed(@SuppressWarnings(  "  unused  "  ) ActionEvent e) {
              System.out.println(  "  Quit  "  );
              System.exit(0);
          }
      };
      addMenuItem(m, KeyStroke.getKeyStroke('q'), quitaction);

      final JFrame f1 = frame;
      Action closeaction = new AbstractAction(  "  Close JFrame (Bug will disappear)  "  ) {
          @Override public void actionPerformed(@SuppressWarnings(  "  unused  "  ) ActionEvent e) {
              System.out.println(  "  Closing window.  Bug will disappear  "  );
              f1.setVisible(false);
          }
      };

      addMenuItem(m, KeyStroke.getKeyStroke('c'), closeaction);
      // ?? when the jframe is dismissed, the DELETE bug goes away.


      jmb.add(m);
      frame.setJMenuBar(jmb);
      frame.add(new JLabel(  "     Press some keys (see Action menu)     "  ));
      frame.pack();
      frame.setVisible(true);
      System.out.println(  "  Ready  "  );
  }

  private static void addMenuItem(JMenu m, KeyStroke key, Action action) {
      action.putValue(Action.ACCELERATOR_KEY, key);
      m.add(action);
      System.out.println(  "  added   "   + action.getValue(Action.NAME));
  }

  private static AbstractAction quickieAction(final String keyname) {
      return new AbstractAction(keyname) {
          @Override public void actionPerformed(@SuppressWarnings(  "  unused  "  ) ActionEvent e) {
              System.out.println(keyname);
          }
      };
  }

}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
No workaround.
Comments
javax/swing/JMenuItem/ActionListenerCalledTwice/ActionListenerCalledTwiceTest.java PASSED under JDK 8 b132 on MacOS, Linux, Solaris, Windows. Closed issue as Fixed/Verified.
11-03-2014

The regression test javax/swing/JMenuItem/ActionListenerCalledTwice/ActionListenerCalledTwiceTest.java has been modified to accommodate problematic key strokes.
06-09-2013

Only Modifier+ENTER combinations are affected.
14-08-2013

I am not able to reproduce the issue with the JDK 7u40_b38 (build 1.7.0_40-ea-fastdebug-b38) I run the application, opened the menu item and pressed Control-Enter and Cmd-Enter. Only one event is shown in the console for each key.
14-08-2013

what is introduced in release? we need evaluation today
14-08-2013