Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8284445

macOS 12 prints a warning when a function key shortcut is assigned to a menu

XMLWordPrintable

    • b17
    • generic
    • os_x

      ADDITIONAL SYSTEM INFORMATION :
      OpenJFX 18, OpenJDK 18, macOS 12.3.1 (aarch64)

      A DESCRIPTION OF THE PROBLEM :
      When a JavaFX application assigns function-key shortcuts to items in the system menu bar, macOS prints a warning of the following form for each such shortcut:

      java[25853:400800] NSEventModifierFlagFunction specified to -setKeyEquivalentModifierMask: for item <NSMenuItem: 0x600001231c00 Find next, ke='Command-F3'>, but is only supported for system-provided menu items; will not be used

      This does not appear to affect functionality at present, but is clogging up logs since the offending code can be executed many times.

      The cause appears to be in com.sun.javafx.tk.quantum.GlassSystemMenu#glassModifiers, which appears to add MODIFIER_FUNCTION to any shortcut that uses F1-F24. This may be required on some platforms but I believe it should not do this on macOS, since the fn modifier is not a part of the shortcut and the OS does not permit applications to use it.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Call MenuItem.setAccelerator with a KeyCodeCombination using a function key, add the menu item in question to a MenuBar whose useSystemMenuBar property is true, and run the code on a recent macOS.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The requested shortcut is assigned uneventfully
      ACTUAL -
      The requested shortcut is assigned, but the OS prints warnings about unsupported behavior

      ---------- BEGIN SOURCE ----------
      package repro;

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.*;
      import javafx.scene.input.KeyCodeCombination;
      import javafx.scene.layout.VBox;
      import javafx.stage.Stage;

      public class Reproduction extends Application {
          @Override
          public void start(Stage stage) {
              var item = new MenuItem("Warns");
              item.setAccelerator(KeyCodeCombination.keyCombination("F1"));
              var menu = new Menu("Menu");
              menu.getItems().add(item);
              var root = new VBox();
              var mbar = new MenuBar();
              mbar.setUseSystemMenuBar(true);
              mbar.getMenus().add(menu);
              root.getChildren().add(mbar);
              stage.setScene(new Scene(root));
              stage.show();
          }
      }

      // also needs module-info.java:
      //
      // module repro {
      // requires javafx.controls;
      // exports repro;
      // }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Ignore the warnings and pray they never get turned into errors

      FREQUENCY : always


            arapte Ambarish Rapte
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: