JDK-8032579 : Incorrect FocusTraversalPolicy with mixed AWT/Swing toplevels
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7u4,7u40,7u51,8,8u20
  • Priority: P2
  • Status: Resolved
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 2014-01-23
  • Updated: 2014-01-30
  • Resolved: 2014-01-24
Related Reports
Relates :  
Relates :  
Description
In case an application uses Swing and AWT toplevels all together, and a Swing toplevel is initialised first then all subsequent AWT topleves get swing FocusTraversalPolicy, which is LayoutFocusTraversalPolicy. However, the correct default FTP for an AWT toplevel is DefaultFocusTraversalPolicy (unless a developer explicitly sets another FTP).

The test case:

import java.awt.Frame;
import javax.swing.JFrame;

public class FocusPolicyTest {
    public static void main(String[] args) {
        JFrame f0 = new JFrame("Swing");
        f0.setVisible(true);
        System.out.println("FTP for Swing: " + f0.getFocusTraversalPolicy());
        
        Frame f1 = new Frame("AWT");
        f1.setVisible(true);
        System.out.println("FTP for AWT: " + f1.getFocusTraversalPolicy());
    }
}

Comments
Closing the bug as not an issue, according to the comment above.
24-01-2014

As it appeared, the Focus Spec (http://docs.oracle.com/javase/7/docs/api/java/awt/doc-files/FocusSpec.html) explicitly mentions the case with a mixed Swing/AWT app: <<Swing applications, or mixed Swing/AWT applications, that use one of the standard look and feels, or any other look and feel derived from BasicLookAndFeel, will use LayoutFocusTraversalPolicy for all Containers by default. All other applications, including pure AWT applications, will use DefaultFocusTraversalPolicy by default.>> Thus, the original JCK test (JCK-7302082) fails because it doesn't take into account that an AWT frame gets LayoutFocusTraversalPolicy on its initialization. From the other side, LayoutFocusTraversalPolicy is not a good choice for an AWT frame as it may lead to an unexpected focus traversal order (as in the test). However, an app that mixes Swing and AWT frame is not a common case, so I think we're free to leave the behavior and the spec as is. Just for the history, here's the fix that changes the behavior so that a frame gets correct focus policy unless a custom policy is explicitly set on the KeyboardFocusManager: http://cr.openjdk.java.net/~ant/JDK-8032579/webrev.0
24-01-2014

the test is excluded already, so I'm removing tck-red label and in such condition this is P2 regression
24-01-2014

AlexeyF, why labeled tck-red if the test was excluded by another reason? (should it be tck-exclude)?
24-01-2014

If this conformance test fails in earlier releases, why is it a tck-red issue for JDK 8? Shouldn't the test simply be excluded?
23-01-2014

the fix is almost ready, 8-critical-request will be filed soon
23-01-2014

My guess is that it missed because test cases failed only when run separately. I doubt that this mode included in test matrix.
23-01-2014

Why doesn't detected by ATR (AllTestRun) ??
23-01-2014

is it affected jdk 8?
23-01-2014

Affected JCk test: api/java_awt/awt_focus_subsystem/event_delivery/index.html#EventDelivery The following its test cases failed due to this issue when run separately: EventDelivery_hw_0002, EventDelivery_hw_0005, EventDelivery_hw_0006, EventDelivery_lw_0005, EventDelivery_lw_0006. %JAVA_DIR%\bin\java -classpath %JCK_DIR%\classes javasoft.sqe.tests.api.java.awt.Event.awt_focus_subsystem.event_delivery.EventDeliveryTests -platform.crossWindowFocusTransferSupported true -timeoutFactor 1.0 -TestCaseID EventDelivery_hw_0002 For details please see JCK-7302082. Marked as P1, conformance, tck-red.
23-01-2014

This is a regression of 7125044. The fix for that bug (http://cr.openjdk.java.net/~ant/7125044/webrev.3) didn't take into account the case of mixed toplevels.
23-01-2014