# HG changeset patch # User pchelko # Date 1395239251 -14400 # Node ID f985a8f16d58fdd76080b29c8db0a5cd0d5157b6 # Parent 7908c1a34e3acb231a6012689242a829d6a790d4 8037776: [macosx] Swing app fails to exit after last window is disposed when security manager is enabled Reviewed-by: anthony, serb diff -r 7908c1a34e3a -r f985a8f16d58 jdk/src/macosx/classes/sun/lwawt/macosx/CWarningWindow.java --- a/jdk/src/macosx/classes/sun/lwawt/macosx/CWarningWindow.java Wed Mar 19 16:13:59 2014 +0400 +++ b/jdk/src/macosx/classes/sun/lwawt/macosx/CWarningWindow.java Wed Mar 19 18:27:31 2014 +0400 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 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 @@ -39,6 +39,8 @@ import java.awt.event.MouseEvent; import java.awt.geom.Point2D; import java.lang.ref.WeakReference; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledFuture; @@ -321,6 +323,15 @@ }; } + @Override + public void dispose() { + AccessController.doPrivileged((PrivilegedAction) () -> { + scheduler.shutdown(); + return null; + }); + super.dispose(); + } + private void updateIconSize() { int newSize = -1; diff -r 7908c1a34e3a -r f985a8f16d58 jdk/test/java/awt/security/WarningWindowDisposeTest/WarningWindowDisposeTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/jdk/test/java/awt/security/WarningWindowDisposeTest/WarningWindowDisposeTest.java Wed Mar 19 18:27:31 2014 +0400 @@ -0,0 +1,90 @@ +/* + * 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 8037776 + @summary tests that the WarningWindow is properly disposed + @author Petr Pchelko + @library ../../regtesthelpers/process + @build ProcessResults ProcessCommunicator + @run main WarningWindowDisposeTest +*/ + +import sun.applet.AppletSecurity; +import sun.awt.SunToolkit; + +import java.awt.*; +import java.awt.Toolkit; +import java.util.concurrent.atomic.AtomicBoolean; + +import test.java.awt.regtesthelpers.process.ProcessCommunicator; +import test.java.awt.regtesthelpers.process.ProcessResults; + +public class WarningWindowDisposeTest { + + public static void main(String[] args) { + final AtomicBoolean passed = new AtomicBoolean(false); + new Thread(() -> { + try { + Thread.sleep(5000); + } catch (InterruptedException e) { + throw new RuntimeException("Test FAILED!", e); + } + if (!passed.get()) { + throw new RuntimeException("Test FAILED! The child process never exits"); + } + }, "TimeoutThread").start(); + + String classpath = System.getProperty("java.class.path"); + ProcessResults pres = ProcessCommunicator.executeChildProcess(TestApplication.class, classpath, new String[0]); + passed.set(true); + if (pres.getStdErr() != null && pres.getStdErr().length() > 0) { + System.err.println("========= Child VM System.err ========"); + System.err.print(pres.getStdErr()); + System.err.println("======================================"); + } + + if (pres.getStdOut() != null && pres.getStdOut().length() > 0) { + System.err.println("========= Child VM System.out ========"); + System.err.print(pres.getStdOut()); + System.err.println("======================================"); + } + } + + public static class TestApplication { + public static void main(String[] args) throws Exception { + System.setSecurityManager(new AppletSecurity() { + @Override + public void checkPackageAccess (String s){ + } + }); + Frame f = new Frame("Test frame"); + f.setVisible(true); + ((SunToolkit) Toolkit.getDefaultToolkit()).realSync(); + Thread.sleep(500); + f.setVisible(false); + f.dispose(); + } + } +}