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