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

KeyBinding.getSpecificity does not handle OptionalBoolean.ANY correctly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8u60
    • 7u71, 8u25
    • javafx
    • Fault seen on Linux and OSX.

      The getSpecificity code repeatedly tests whether the shift option is ANY when looking at the settings of ctrl, alt, and meta. The resulting calculated value is incorrect if the ANY setting is used. This could result in unexpected key binding matches in control behaviour.

      JUnit test:

      package com.sun.javafx.scene.control.behavior;

      import javafx.scene.input.KeyCode;
      import javafx.scene.input.KeyEvent;
      import org.junit.Test;
      import static org.junit.Assert.*;

      public class KeyBindingTest
      {
          @Test
          public void getSpecificity()
          {
      KeyCode code = KeyCode.ENTER;
      KeyBinding uut;
      KeyEvent event;

      // Expected answer:
      // 1 pt for matching key code
      // 1 pt for matching key event type
      // 1 pt for matching no alt
      // 1 pt for matching no meta
      // 1 pt for matching shift or control
      // 0 pt for the other optional value of control/shift
      //
      // Total = 5.
      //
      int expect = 5;

      uut = new KeyBinding(code, "ShiftEnter").shift().ctrl(OptionalBoolean.ANY);

      event = new KeyEvent(KeyEvent.KEY_PRESSED, null,
                      null, code, true, false, false, false);

      assertEquals(expect, uut.getSpecificity(null, event)); // Gets 6 (fx 2.2, fx 8)

      uut = new KeyBinding(code, "CtrlEnter").shift(OptionalBoolean.ANY).ctrl();

      event = new KeyEvent(KeyEvent.KEY_PRESSED, null,
                      null, code, false, true, false, false);

      assertEquals(expect, uut.getSpecificity(null, event)); // Gets 2 (fx 2.2, fx 8)
          }
      }

            jgiles Jonathan Giles
            dcooke David Cooke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: