JDK-8075943 : IllegalArgumentException when transferring focus from JRadioButton Using Tab
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 7u80,8u40
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • OS: linux_ubuntu
  • CPU: x86_64
  • Submitted: 2015-03-23
  • Updated: 2015-04-29
  • Resolved: 2015-03-27
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 8 JDK 9
8u60Resolved 9Resolved
Related Reports
Duplicate :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b25)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

A DESCRIPTION OF THE PROBLEM :
Transferring focus from a JRadioButton to the next component with the keyboard causes an Exception to occur when if the component's Window is not the FocusCycleRoot for that component.

The same code works fine on Java 7.

I suspect the code changes from JDK-8033699 caused this regression.


javax.swing.plaf.basic.BasicRadioButtonUI.ButtonGroupInfo.getFocusTransferBaseComponent(boolean)
should probably use the focusCycleRoot for the JRadioButton as 'container', but instead uses the Window that holds the component.
The result is the same if the Window is the FocusCycleRoot, but that is not always the case.

Window container = SwingUtilities.getWindowAncestor(activeBtn);
should probably be replaced by
Container container = activeBtn.getFocusCycleRootAncestor();

REGRESSION.  Last worked in version 7u76

ADDITIONAL REGRESSION INFORMATION: 
java version "1.7.0_76"
Java(TM) SE Runtime Environment (build 1.7.0_76-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.76-b04, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
- Run the main method of the class provided. A window appears. Radio button 'Option 1' has the focus.
- Press the tab key

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Focus should be transferred to a different component
ACTUAL -
An exception is thrown and focus was not transferred

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.BorderLayout;
import javax.swing.*;

public class FocusCycleRootTest
{
    public static void main(String[] args)
    {
        JFrame window = new JFrame("Test");
        window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        
        JPanel rootPanel = new JPanel();
        rootPanel.setLayout(new BorderLayout());
        
        JPanel formPanel = new JPanel();
        formPanel.setFocusTraversalPolicy(new LayoutFocusTraversalPolicy());
        formPanel.setFocusCycleRoot(true);
        
        JRadioButton option1 = new JRadioButton("Option 1", true);
        JRadioButton option2 = new JRadioButton("Option 2");
        
        ButtonGroup radioButtonGroup = new ButtonGroup();
        radioButtonGroup.add(option1);
        radioButtonGroup.add(option2);
        
        formPanel.add(option1);
        formPanel.add(option2);
        formPanel.add(new JTextField("Another focusable component"));
        
        rootPanel.add(formPanel, BorderLayout.CENTER);
        
        JButton okButton = new JButton("OK");
        rootPanel.add(okButton, BorderLayout.SOUTH);
        
        window.add(rootPanel);
        window.pack();
        window.setVisible(true);
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
use the mouse to transfer focus


Comments
This is a duplicate of the issue JDK-8075609 java.lang.IllegalArgumentException: aContainer is not a focus cycle root of aComponent
27-03-2015

Alexandr, please evaluate this issue
27-03-2015

Looks like a dup of JDK-8075609, which is a customer bug.
26-03-2015

Created back port target to 8u60
26-03-2015

1) Run the attached test case(FocusCycleRootTest.java). 2) Checked this on a Windows 7 (64-bit) system for 7u76, 7u80, 8u31, 8u40, 8u60 b07. The issue is reproducible with JDK 7u80, 8u40, and 8u60. This is a regression. **************************************************************************************** 7u76: OK 7u80: FAIL 8u31 : OK 8u40: FAIL 8u60 ea b07: FAIL ****************************************************************************************** 3) Output of the testcase with 8u40: run: Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: aContainer is not a focus cycle root of aComponent at javax.swing.SortingFocusTraversalPolicy.getComponentAfter(SortingFocusTraversalPolicy.java:305) at javax.swing.LayoutFocusTraversalPolicy.getComponentAfter(LayoutFocusTraversalPolicy.java:106) at javax.swing.plaf.basic.BasicRadioButtonUI$ButtonGroupInfo.getFocusTransferBaseComponent(BasicRadioButtonUI.java:444) at javax.swing.plaf.basic.BasicRadioButtonUI$ButtonGroupInfo.jumpToNextComponent(BasicRadioButtonUI.java:567) at javax.swing.plaf.basic.BasicRadioButtonUI$KeyHandler.keyPressed(BasicRadioButtonUI.java:597) at java.awt.Component.processKeyEvent(Component.java:6483) at javax.swing.JComponent.processKeyEvent(JComponent.java:2832) at java.awt.Component.processEvent(Component.java:6302) at java.awt.Container.processEvent(Container.java:2234) at java.awt.Component.dispatchEventImpl(Component.java:4881) at java.awt.Container.dispatchEventImpl(Container.java:2292) at java.awt.Component.dispatchEvent(Component.java:4703) at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1954) at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:806) at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1074) at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:945) at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:771) at java.awt.Component.dispatchEventImpl(Component.java:4752) at java.awt.Container.dispatchEventImpl(Container.java:2292) at java.awt.Window.dispatchEventImpl(Window.java:2750) at java.awt.Component.dispatchEvent(Component.java:4703) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:751) at java.awt.EventQueue.access$500(EventQueue.java:97) at java.awt.EventQueue$3.run(EventQueue.java:702) at java.awt.EventQueue$3.run(EventQueue.java:696) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86) at java.awt.EventQueue$4.run(EventQueue.java:724) at java.awt.EventQueue$4.run(EventQueue.java:722) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75) at java.awt.EventQueue.dispatchEvent(EventQueue.java:721) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93) at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
25-03-2015