rt/emul/compact/src/main/java/java/util/concurrent/Executors.java
changeset 1895 bfaf3300b7ba
parent 1890 212417b74b72
     1.1 --- a/rt/emul/compact/src/main/java/java/util/concurrent/Executors.java	Sat Mar 19 10:46:31 2016 +0100
     1.2 +++ b/rt/emul/compact/src/main/java/java/util/concurrent/Executors.java	Sat Mar 19 12:51:03 2016 +0100
     1.3 @@ -36,13 +36,9 @@
     1.4  package java.util.concurrent;
     1.5  import java.util.*;
     1.6  import java.util.concurrent.atomic.AtomicInteger;
     1.7 -import java.security.AccessControlContext;
     1.8  import java.security.AccessController;
     1.9  import java.security.PrivilegedAction;
    1.10  import java.security.PrivilegedExceptionAction;
    1.11 -import java.security.PrivilegedActionException;
    1.12 -import java.security.AccessControlException;
    1.13 -import sun.security.util.SecurityConstants;
    1.14  
    1.15  /**
    1.16   * Factory and utility methods for {@link Executor}, {@link
    1.17 @@ -350,7 +346,7 @@
    1.18       * class loader.
    1.19       */
    1.20      public static ThreadFactory privilegedThreadFactory() {
    1.21 -        return new PrivilegedThreadFactory();
    1.22 +        throw new SecurityException();
    1.23      }
    1.24  
    1.25      /**
    1.26 @@ -450,9 +446,7 @@
    1.27       * class loader.
    1.28       */
    1.29      public static <T> Callable<T> privilegedCallableUsingCurrentClassLoader(Callable<T> callable) {
    1.30 -        if (callable == null)
    1.31 -            throw new NullPointerException();
    1.32 -        return new PrivilegedCallableUsingCurrentClassLoader<T>(callable);
    1.33 +        throw new SecurityException();
    1.34      }
    1.35  
    1.36      // Non-public classes supporting the public methods
    1.37 @@ -478,76 +472,13 @@
    1.38       */
    1.39      static final class PrivilegedCallable<T> implements Callable<T> {
    1.40          private final Callable<T> task;
    1.41 -        private final AccessControlContext acc;
    1.42  
    1.43          PrivilegedCallable(Callable<T> task) {
    1.44              this.task = task;
    1.45 -            this.acc = AccessController.getContext();
    1.46          }
    1.47  
    1.48          public T call() throws Exception {
    1.49 -            try {
    1.50 -                return AccessController.doPrivileged(
    1.51 -                    new PrivilegedExceptionAction<T>() {
    1.52 -                        public T run() throws Exception {
    1.53 -                            return task.call();
    1.54 -                        }
    1.55 -                    }, acc);
    1.56 -            } catch (PrivilegedActionException e) {
    1.57 -                throw e.getException();
    1.58 -            }
    1.59 -        }
    1.60 -    }
    1.61 -
    1.62 -    /**
    1.63 -     * A callable that runs under established access control settings and
    1.64 -     * current ClassLoader
    1.65 -     */
    1.66 -    static final class PrivilegedCallableUsingCurrentClassLoader<T> implements Callable<T> {
    1.67 -        private final Callable<T> task;
    1.68 -        private final AccessControlContext acc;
    1.69 -        private final ClassLoader ccl;
    1.70 -
    1.71 -        PrivilegedCallableUsingCurrentClassLoader(Callable<T> task) {
    1.72 -            SecurityManager sm = System.getSecurityManager();
    1.73 -            if (sm != null) {
    1.74 -                // Calls to getContextClassLoader from this class
    1.75 -                // never trigger a security check, but we check
    1.76 -                // whether our callers have this permission anyways.
    1.77 -                sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
    1.78 -
    1.79 -                // Whether setContextClassLoader turns out to be necessary
    1.80 -                // or not, we fail fast if permission is not available.
    1.81 -                sm.checkPermission(new RuntimePermission("setContextClassLoader"));
    1.82 -            }
    1.83 -            this.task = task;
    1.84 -            this.acc = AccessController.getContext();
    1.85 -            this.ccl = Thread.currentThread().getContextClassLoader();
    1.86 -        }
    1.87 -
    1.88 -        public T call() throws Exception {
    1.89 -            try {
    1.90 -                return AccessController.doPrivileged(
    1.91 -                    new PrivilegedExceptionAction<T>() {
    1.92 -                        public T run() throws Exception {
    1.93 -                            ClassLoader savedcl = null;
    1.94 -                            Thread t = Thread.currentThread();
    1.95 -                            try {
    1.96 -                                ClassLoader cl = t.getContextClassLoader();
    1.97 -                                if (ccl != cl) {
    1.98 -                                    t.setContextClassLoader(ccl);
    1.99 -                                    savedcl = cl;
   1.100 -                                }
   1.101 -                                return task.call();
   1.102 -                            } finally {
   1.103 -                                if (savedcl != null)
   1.104 -                                    t.setContextClassLoader(savedcl);
   1.105 -                            }
   1.106 -                        }
   1.107 -                    }, acc);
   1.108 -            } catch (PrivilegedActionException e) {
   1.109 -                throw e.getException();
   1.110 -            }
   1.111 +            return task.call();
   1.112          }
   1.113      }
   1.114  
   1.115 @@ -556,23 +487,19 @@
   1.116       */
   1.117      static class DefaultThreadFactory implements ThreadFactory {
   1.118          private static final AtomicInteger poolNumber = new AtomicInteger(1);
   1.119 -        private final ThreadGroup group;
   1.120          private final AtomicInteger threadNumber = new AtomicInteger(1);
   1.121          private final String namePrefix;
   1.122  
   1.123          DefaultThreadFactory() {
   1.124 -            SecurityManager s = System.getSecurityManager();
   1.125 -            group = (s != null) ? s.getThreadGroup() :
   1.126 -                                  Thread.currentThread().getThreadGroup();
   1.127              namePrefix = "pool-" +
   1.128                            poolNumber.getAndIncrement() +
   1.129                           "-thread-";
   1.130          }
   1.131  
   1.132          public Thread newThread(Runnable r) {
   1.133 -            Thread t = new Thread(group, r,
   1.134 -                                  namePrefix + threadNumber.getAndIncrement(),
   1.135 -                                  0);
   1.136 +            Thread t = new Thread(r,
   1.137 +                                  namePrefix + threadNumber.getAndIncrement()
   1.138 +                                  );
   1.139              if (t.isDaemon())
   1.140                  t.setDaemon(false);
   1.141              if (t.getPriority() != Thread.NORM_PRIORITY)
   1.142 @@ -582,44 +509,6 @@
   1.143      }
   1.144  
   1.145      /**
   1.146 -     * Thread factory capturing access control context and class loader
   1.147 -     */
   1.148 -    static class PrivilegedThreadFactory extends DefaultThreadFactory {
   1.149 -        private final AccessControlContext acc;
   1.150 -        private final ClassLoader ccl;
   1.151 -
   1.152 -        PrivilegedThreadFactory() {
   1.153 -            super();
   1.154 -            SecurityManager sm = System.getSecurityManager();
   1.155 -            if (sm != null) {
   1.156 -                // Calls to getContextClassLoader from this class
   1.157 -                // never trigger a security check, but we check
   1.158 -                // whether our callers have this permission anyways.
   1.159 -                sm.checkPermission(SecurityConstants.GET_CLASSLOADER_PERMISSION);
   1.160 -
   1.161 -                // Fail fast
   1.162 -                sm.checkPermission(new RuntimePermission("setContextClassLoader"));
   1.163 -            }
   1.164 -            this.acc = AccessController.getContext();
   1.165 -            this.ccl = Thread.currentThread().getContextClassLoader();
   1.166 -        }
   1.167 -
   1.168 -        public Thread newThread(final Runnable r) {
   1.169 -            return super.newThread(new Runnable() {
   1.170 -                public void run() {
   1.171 -                    AccessController.doPrivileged(new PrivilegedAction<Void>() {
   1.172 -                        public Void run() {
   1.173 -                            Thread.currentThread().setContextClassLoader(ccl);
   1.174 -                            r.run();
   1.175 -                            return null;
   1.176 -                        }
   1.177 -                    }, acc);
   1.178 -                }
   1.179 -            });
   1.180 -        }
   1.181 -    }
   1.182 -
   1.183 -    /**
   1.184       * A wrapper class that exposes only the ExecutorService methods
   1.185       * of an ExecutorService implementation.
   1.186       */