United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-8022997 : [macosx] Remaining duplicated key events

Details
Type:
Bug
Submit Date:
2013-08-13
Status:
Resolved
Updated Date:
2013-08-16
Project Name:
JDK
Resolved Date:
2013-08-14
Component:
client-libs
OS:
os_x
Sub-Component:
javax.swing
CPU:
Priority:
P3
Resolution:
Fixed
Affected Versions:
7u6,7u40,8
Fixed Versions:

Related Reports
Backport:

Sub Tasks

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
what is introduced in release? we need evaluation today
                                     
2013-08-14
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.
                                     
2013-08-14
Only Modifier+ENTER combinations are affected.
                                     
2013-08-14
URL:   http://hg.openjdk.java.net/jdk8/awt/jdk/rev/3930a827160a
User:  leonidr
Date:  2013-08-14 21:18:38 +0000

                                     
2013-08-14



Hardware and Software, Engineered to Work Together