1 /*
   2  * Copyright (c) 2013, 2016, 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  * @modules java.desktop/sun.awt
  34  *          java.logging
  35  * @build TestMainAppContext
  36  * @run main/othervm TestMainAppContext
  37  * @author danielfuchs
  38  */
  39 public class TestMainAppContext {
  40 
  41     static volatile Throwable thrown = null;
  42 
  43     public static void main(String... args) throws Exception {
  44         ThreadGroup rootTG = Thread.currentThread().getThreadGroup();
  45         while (rootTG.getParent() != null) {
  46             rootTG = rootTG.getParent();
  47         }
  48 
  49         ThreadGroup tg = new ThreadGroup(rootTG, "FakeApplet");
  50         final Thread t1 = new Thread(tg, "createNewAppContext") {
  51             @Override
  52             public void run() {
  53                 try {
  54                     AppContext context = SunToolkit.createNewAppContext();
  55                 } catch(Throwable t) {
  56                     thrown = t;
  57                 }
  58             }
  59         };
  60         t1.start();
  61         t1.join();
  62         if (thrown != null) {
  63             throw new RuntimeException("Unexpected exception: " + thrown, thrown);
  64         }
  65         Thread t2 = new Thread(tg, "BugDetector") {
  66 
  67             @Override
  68             public void run() {
  69                 try {
  70                     Logger.getLogger("foo").info("Done");
  71                 } catch (Throwable x) {
  72                     thrown = x;
  73                 }
  74             }
  75 
  76         };
  77 
  78         System.setSecurityManager(new SecurityManager());
  79         t2.start();
  80         t2.join();
  81         if (thrown != null) {
  82             throw new RuntimeException("Test failed: " + thrown, thrown);
  83         }
  84 
  85     }
  86 
  87 }