ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/ForkJoinPool9Test.java
Revision: 1.2
Committed: Tue Jan 31 01:44:39 2017 UTC (7 years, 3 months ago) by jsr166
Branch: MAIN
Changes since 1.1: +12 -1 lines
Log Message:
JDK-8172726: ForkJoin common pool retains a reference to the thread context class loader

File Contents

# User Rev Content
1 jsr166 1.1 /*
2     * Written by Doug Lea and Martin Buchholz with assistance from
3     * members of JCP JSR-166 Expert Group and released to the public
4     * domain, as explained at
5     * http://creativecommons.org/publicdomain/zero/1.0/
6     */
7    
8     import java.lang.invoke.MethodHandles;
9     import java.lang.invoke.VarHandle;
10     import java.util.concurrent.CompletableFuture;
11    
12     import junit.framework.Test;
13     import junit.framework.TestSuite;
14    
15     public class ForkJoinPool9Test extends JSR166TestCase {
16     public static void main(String[] args) {
17     main(suite(), args);
18     }
19    
20     public static Test suite() {
21     return new TestSuite(ForkJoinPool9Test.class);
22     }
23    
24     /**
25     * Check handling of common pool thread context class loader
26     */
27     public void testCommonPoolThreadContextClassLoader() throws Throwable {
28     if (!testImplementationDetails) return;
29     VarHandle CCL =
30     MethodHandles.privateLookupIn(Thread.class, MethodHandles.lookup())
31     .findVarHandle(Thread.class, "contextClassLoader", ClassLoader.class);
32     ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
33 jsr166 1.2 boolean haveSecurityManager = (System.getSecurityManager() != null);
34 jsr166 1.1 CompletableFuture.runAsync(
35     () -> {
36     assertSame(systemClassLoader,
37     Thread.currentThread().getContextClassLoader());
38     assertSame(systemClassLoader,
39     CCL.get(Thread.currentThread()));
40 jsr166 1.2 if (haveSecurityManager)
41     assertThrows(
42     SecurityException.class,
43     () -> System.getProperty("foo"),
44     () -> Thread.currentThread().setContextClassLoader(null));
45    
46     // TODO ?
47     // if (haveSecurityManager
48     // && Thread.currentThread().getClass().getSimpleName()
49     // .equals("InnocuousForkJoinWorkerThread"))
50     // assertThrows(SecurityException.class, /* ?? */);
51 jsr166 1.1 }).join();
52     }
53    
54     }