Mercurial > hg > icedtea8-forest > jdk
changeset 10624:eb459e6ac74a jdk8u20-b32
8047288: Fixes endless loop on mac caused by invoking Windows.isFocusable() on Appkit thread.
Reviewed-by: ant, pchelko
Contributed-by: artem.malinko@oracle.com
author | mcherkas |
---|---|
date | Tue, 29 Jul 2014 15:52:50 +0400 |
parents | 2b3f6039a4e4 |
children | 595326901edf |
files | src/macosx/classes/sun/lwawt/LWWindowPeer.java test/java/awt/Focus/WindowIsFocusableAccessByThreadsTest/WindowIsFocusableAccessByThreadsTest.java |
diffstat | 2 files changed, 119 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/LWWindowPeer.java Thu Aug 14 12:30:55 2014 -0700 +++ b/src/macosx/classes/sun/lwawt/LWWindowPeer.java Tue Jul 29 15:52:50 2014 +0400 @@ -105,6 +105,8 @@ private final SecurityWarningWindow warningWindow; + private volatile boolean targetFocusable; + /** * Current modal blocker or null. * @@ -240,13 +242,12 @@ if (!visible && warningWindow != null) { warningWindow.setVisible(false, false); } - + updateFocusableWindowState(); super.setVisibleImpl(visible); // TODO: update graphicsConfig, see 4868278 platformWindow.setVisible(visible); if (isSimpleWindow()) { KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance(); - if (visible) { if (!getTarget().isAutoRequestFocus()) { return; @@ -397,6 +398,7 @@ @Override public void updateFocusableWindowState() { + targetFocusable = getTarget().isFocusableWindow(); platformWindow.updateFocusableWindowState(); } @@ -1220,13 +1222,13 @@ } private boolean isFocusableWindow() { - boolean focusable = getTarget().isFocusableWindow(); + boolean focusable = targetFocusable; if (isSimpleWindow()) { LWWindowPeer ownerPeer = getOwnerFrameDialog(this); if (ownerPeer == null) { return false; } - return focusable && ownerPeer.getTarget().isFocusableWindow(); + return focusable && ownerPeer.targetFocusable; } return focusable; }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/java/awt/Focus/WindowIsFocusableAccessByThreadsTest/WindowIsFocusableAccessByThreadsTest.java Tue Jul 29 15:52:50 2014 +0400 @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + @test + @bug 8047288 + @summary Tests method isFocusable of Window component. It should be accessed only from EDT + @author artem.malinko@oracle.com + @library ../../regtesthelpers + @build Util + @run main WindowIsFocusableAccessByThreadsTest +*/ + +import test.java.awt.regtesthelpers.Util; + +import javax.swing.*; +import java.awt.*; +import java.util.concurrent.atomic.AtomicBoolean; + +public class WindowIsFocusableAccessByThreadsTest { + private static AtomicBoolean testPassed = new AtomicBoolean(true); + private static volatile TestFrame frame; + private static volatile TestWindow window; + private static volatile Button openWindowBtn; + + public static void main(String[] args) { + frame = new TestFrame("Test EDT access to Window components"); + window = new TestWindow(frame); + + SwingUtilities.invokeLater(WindowIsFocusableAccessByThreadsTest::init); + + Util.waitTillShown(frame); + Robot robot = Util.createRobot(); + Util.clickOnComp(frame, robot, 100); + Util.clickOnComp(openWindowBtn, robot, 100); + + Util.waitTillShown(window); + + if (!testPassed.get()) { + throw new RuntimeException("Window component methods has been accessed not " + + "from Event Dispatching Thread"); + } + } + + private static void init() { + frame.setSize(400, 400); + frame.setLayout(new FlowLayout()); + openWindowBtn = new Button("open window"); + openWindowBtn.addActionListener(e -> { + window.setSize(100, 100); + window.setLocation(400, 100); + window.setVisible(true); + }); + frame.add(openWindowBtn); + frame.setVisible(true); + } + + private static void testThread() { + if (!SwingUtilities.isEventDispatchThread()) { + testPassed.set(false); + } + } + + private static class TestWindow extends Window { + public TestWindow(Frame owner) { + super(owner); + } + + // isFocusable method is final and we can't add this test to it. + // But it invokes getFocusableWindowState and here we can check + // if thread is EDT. + @Override + public boolean getFocusableWindowState() { + testThread(); + return super.getFocusableWindowState(); + } + } + + private static class TestFrame extends Frame { + private TestFrame(String title) throws HeadlessException { + super(title); + } + + // isFocusable method is final and we can't add this test to it. + // But it invokes getFocusableWindowState and here we can check + // if thread is EDT. + @Override + public boolean getFocusableWindowState() { + testThread(); + return super.getFocusableWindowState(); + } + } +}