JDK-8020510 : [macosx] Duplicated key events, depending on the presence of a JFrame
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7u25
  • Priority: P3
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: os_x
  • Submitted: 2013-07-11
  • Updated: 2013-07-16
  • Resolved: 2013-07-16
Description
FULL PRODUCT VERSION :
java version  " 1.7.0_25 " 
Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Mac OSX 10.8.4 (12E55)

A DESCRIPTION OF THE PROBLEM :
Some key events, set as accelerators for JMenuBar items, are being processed in duplicate.  The apple useScreenMenuBar property must be set to show the bug, and it goes away when the JFrame is hidden.

The could be related to the closed bug 8008366.  The fix there (which I don't believe I have yet in my v25 JDK) was submitted with a comment suggesting it was perhaps a shallow or hacky fix. I'm pretty certain that fix doesn't cover what I'm reporting, since I've observed it with other keys.

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=8008366

Affected keys:

delete key: unmodified or with cmd-, alt-, shift-, or control-
backspace key: with control- or command-
(*NOT* alt-, shift-, or unmodified backspace)

The bug is never triggered when selecting the item from the menubar with the mouse.

The bug goes away if you close the JFrame in which case no keys are duplicated.  (to see this in the demo code, press C or just close the window.)

The bug is *not* present in JDK 1.6.


In my full application, this manifests itself as a deletion action (bound to Cmd-backspace) occuring twice, which is obviously serious and confusing to users.

I've included demo code to illustrate the bug.


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 :
I don't think there is a workaround.
Comments
it seems should be closed as NonReproducible
15-07-2013

The test may not be applicable for the JDK 7u6 because I do not see set accelerators in the menu items. I see that the issue is reproduced in build 1.7.0_14-ea-fastdebug-b17 and is not reproduced in build 1.7.0_40-ea-b32. It seems that the issue has been already fixed.
15-07-2013

is it reproducible on 7u6? we should clean up it today
15-07-2013