JDK-8155197 : Focus transition issue
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 8
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2016-04-27
  • Updated: 2018-02-15
  • Resolved: 2017-10-07
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 10 JDK 8
10 b29Fixed 8u162Fixed
There is a focus transition issue during execution of Oracle forms application.

The Forms application has several text fields and a button. When the 1st field has the focus, clicking the button brings up a progress dialog. When the dialog is closed, the focus is expected to stay in the 1st field. It is what happens with JRE 6u43. With JRE 8u31, the focus is moved to another field.
During review it was found that the root cause of the problem for jdk10/9 is different. Semyon Sadetsky: ���Actually the parent frame doesn't own the input focus when the issue happens. The focus is on the dialog already and when FOCUS_GAINED event comes for the dialog the KFM discovers that the dialog should not have the focus and rejects it in line 588 of the DefaultKeyboardFocusManager: ������������������������������������������������������ restoreFocus(fe, newFocusedWindow); This happens when the dialog became non-focusable (non-visible) after the focus request is sent, but before the corresponding FOCUS_GAINED event is handled on the EDT. In this case the focus is directly restored to the previously focused window which doesn't have the focus at this moment and input focus cannot be requested to one of its components synchronously. Please confirm whether you agree on the root cause of the bug.��� More details at http://mail.openjdk.java.net/pipermail/awt-dev/2017-September/013098.html

Problem description: Currently we restore focus synchronously to a component if the window (which contains it) owns the focus. However if another window/dialog is displayed at the same time, the first window loses focus, (i.e. synchronous focus request failed) and the focus target is shifted to the next component in the focus traversal cycle. Fix: It is necessary to check the result of synchronous focus request for a component. If the focus request���s failed because the contained window lost focus, we should restore focus to this component next time when its parent window obtains focus.

Most part of the problem was addressed by JDK-8139218 and JDK-8159432 which were integrated into 9/10, but not down ported to 8u. That explains the differences in behaviour between 8 and 9/10.

The problem is easily reproducible on jdk8u using the steps from above. It also takes place on jdk9/10, but quite intermittently. It is necessary to click Go button several times rapidly to reproduce the issue on 9/10.

Run it with java -jar focus8Test.jar The caret blinks in the first text field. Click Go button. A dialog is quickly shown and hidden. The caret is expected to be in the first text field. If it's not, the test fails. On jdk8 after clicking Go button, the caret is usually in the third text field.

Test case and its source code are in the attachment