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

KeyEvents lost when focused node is removed from the Scene

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 9
    • 8u45
    • javafx
    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.8.0_45"
      Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
      Java HotSpot(TM) Client VM (build 25.45-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 7 x64

      A DESCRIPTION OF THE PROBLEM :
      When a KeyEvent is delivered it is possible for a KeyEvent to arrive between the time a node is removed from the scenegraph and the time is is removed from Scene.getFocusOwner.

      This happens because the Scene.getFocusOwner is cleaned up on the next pulse while the focus owner was removed from the scenegraph during the current pulse. KeyEvents can arrive between these 2 points.

      This results in the event being dispatched to a node not on the scenegraph and prevents a filter or handler added to the scene from being able to handle the events.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use autohotkey or some other macro utility to supply keyboard input while focused nodes are being added and removed from the scene. ie:
      !m::
      IfWinExist, Catapult
      {WinActivate ; use the window found above
       Sleep, 200 ; wait for 200ms
       Send ';5499990123456781=15121015432198712345?
      }

      Note that key events are momentarily missed by the scene filter each time the focused node is removed.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The scene filter should catch all keystrokes while it's stage has focus.
      ACTUAL -
      It is common for a couple of keystrokes to be missed by the scene filter because they are delivered to the scenes focused node, which is no longer actually part of the scene.

      This is a race condition that is difficult to reproduce without a little luck, however, it occurs frequently on some of our slower machines.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      No error message, but not all key strokes are reported.

      REPRODUCIBILITY :
      This bug can be reproduced often.

      ---------- BEGIN SOURCE ----------
      Unable to reproduce with a simple test case, since this is a race condition it's likely that a the issue depends on the delays caused by a larger application.
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Modifying the Scene class in my JRE as follows eliminated all occurrences of this issue for us:

      diff -r 93e3b40039ac modules/graphics/src/main/java/javafx/scene/Scene.java
      --- a/modules/graphics/src/main/java/javafx/scene/Scene.java Mon Mar 16 22:23:39 2015 -0700
      +++ b/modules/graphics/src/main/java/javafx/scene/Scene.java Mon Jun 29 13:46:44 2015 -0400
      @@ -3957,7 +3957,7 @@
               private void process(KeyEvent e) {
                   final Node sceneFocusOwner = getFocusOwner();
                   final EventTarget eventTarget =
      - (sceneFocusOwner != null) ? sceneFocusOwner
      + (sceneFocusOwner != null && sceneFocusOwner.getScene() == Scene.this) ? sceneFocusOwner
                                                     : Scene.this;
       
                   // send the key event to the current focus owner or to scene if


            ekleyman Elina Kleyman (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: