8190482: InnocuousThread creation should not require the caller to possess enableContextClassLoaderOverride
authorchegar
Tue, 07 Nov 2017 17:08:59 +0000
changeset 47709 5e7cf99b1303
parent 47708 8c0c0aec3ae7
child 47710 6b0c555658e8
8190482: InnocuousThread creation should not require the caller to possess enableContextClassLoaderOverride Reviewed-by: rriggs, mchung
src/java.base/share/classes/jdk/internal/misc/InnocuousThread.java
--- a/src/java.base/share/classes/jdk/internal/misc/InnocuousThread.java	Tue Nov 07 12:18:29 2017 +0100
+++ b/src/java.base/share/classes/jdk/internal/misc/InnocuousThread.java	Tue Nov 07 17:08:59 2017 +0000
@@ -62,10 +62,16 @@
      * set to the system class loader.
      */
     public static Thread newThread(String name, Runnable target) {
-        return new InnocuousThread(INNOCUOUSTHREADGROUP,
-                                   target,
-                                   name,
-                                   ClassLoader.getSystemClassLoader());
+        return AccessController.doPrivileged(
+                new PrivilegedAction<Thread>() {
+                    @Override
+                    public Thread run() {
+                        return new InnocuousThread(INNOCUOUSTHREADGROUP,
+                                                   target,
+                                                   name,
+                                                   ClassLoader.getSystemClassLoader());
+                    }
+                });
     }
 
     /**
@@ -80,8 +86,14 @@
      * Returns a new InnocuousThread with null context class loader.
      */
     public static Thread newSystemThread(String name, Runnable target) {
-        return new InnocuousThread(INNOCUOUSTHREADGROUP,
-                                   target, name, null);
+        return AccessController.doPrivileged(
+                new PrivilegedAction<Thread>() {
+                    @Override
+                    public Thread run() {
+                        return new InnocuousThread(INNOCUOUSTHREADGROUP,
+                                                   target, name, null);
+                    }
+                });
     }
 
     private InnocuousThread(ThreadGroup group, Runnable target, String name, ClassLoader tccl) {