1 /* 2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 import java.util.logging.Logger; 24 import sun.awt.AppContext; 25 import sun.awt.SunToolkit; 26 27 28 /** 29 * @test 30 * @bug 8026404 31 * @summary checks that calling getLogger() from a Thread whose ThreadGroup is 32 * a child of the main root group doesn't throw an exception. 33 * @build TestMainAppContext 34 * @run main/othervm TestMainAppContext 35 * @author danielfuchs 36 */ 37 public class TestMainAppContext { 38 39 static volatile Throwable thrown = null; 40 41 public static void main(String... args) throws Exception { 42 ThreadGroup rootTG = Thread.currentThread().getThreadGroup(); 43 while (rootTG.getParent() != null) { 44 rootTG = rootTG.getParent(); 45 } 46 47 ThreadGroup tg = new ThreadGroup(rootTG, "FakeApplet"); 48 final Thread t1 = new Thread(tg, "createNewAppContext") { 49 @Override 50 public void run() { 51 try { 52 AppContext context = SunToolkit.createNewAppContext(); 53 } catch(Throwable t) { 54 thrown = t; 55 } 56 } 57 }; 58 t1.start(); 59 t1.join(); 60 if (thrown != null) { 61 throw new RuntimeException("Unexpected exception: " + thrown, thrown); 62 } 63 Thread t2 = new Thread(tg, "BugDetector") { 64 65 @Override 66 public void run() { 67 try { 68 Logger.getLogger("foo").info("Done"); 69 } catch (Throwable x) { 70 thrown = x; 71 } 72 } 73 74 }; 75 76 System.setSecurityManager(new SecurityManager()); 77 t2.start(); 78 t2.join(); 79 if (thrown != null) { 80 throw new RuntimeException("Test failed: " + thrown, thrown); 81 } 82 83 } 84 85 }