3737
3838import static java .lang .ref .Reference .reachabilityFence ;
3939import java .lang .ref .Cleaner .Cleanable ;
40- import java .security .AccessControlContext ;
41- import java .security .AccessController ;
4240import java .security .PrivilegedAction ;
43- import java .security .PrivilegedActionException ;
4441import java .security .PrivilegedExceptionAction ;
4542import java .util .Collection ;
4643import java .util .List ;
4744import java .util .concurrent .atomic .AtomicInteger ;
4845import jdk .internal .ref .CleanerFactory ;
49- import sun .security .util .SecurityConstants ;
5046
5147/**
5248 * Factory and utility methods for {@link Executor}, {@link
@@ -559,27 +555,13 @@ public String toString() {
559555 */
560556 private static final class PrivilegedCallable <T > implements Callable <T > {
561557 final Callable <T > task ;
562- @ SuppressWarnings ("removal" )
563- final AccessControlContext acc ;
564558
565- @ SuppressWarnings ("removal" )
566559 PrivilegedCallable (Callable <T > task ) {
567560 this .task = task ;
568- this .acc = AccessController .getContext ();
569561 }
570562
571- @ SuppressWarnings ("removal" )
572563 public T call () throws Exception {
573- try {
574- return AccessController .doPrivileged (
575- new PrivilegedExceptionAction <T >() {
576- public T run () throws Exception {
577- return task .call ();
578- }
579- }, acc );
580- } catch (PrivilegedActionException e ) {
581- throw e .getException ();
582- }
564+ return task .call ();
583565 }
584566
585567 public String toString () {
@@ -595,49 +577,26 @@ private static final class PrivilegedCallableUsingCurrentClassLoader<T>
595577 implements Callable <T > {
596578 final Callable <T > task ;
597579 @ SuppressWarnings ("removal" )
598- final AccessControlContext acc ;
599580 final ClassLoader ccl ;
600581
601582 @ SuppressWarnings ("removal" )
602583 PrivilegedCallableUsingCurrentClassLoader (Callable <T > task ) {
603- SecurityManager sm = System .getSecurityManager ();
604- if (sm != null ) {
605- // Calls to getContextClassLoader from this class
606- // never trigger a security check, but we check
607- // whether our callers have this permission anyways.
608- sm .checkPermission (SecurityConstants .GET_CLASSLOADER_PERMISSION );
609-
610- // Whether setContextClassLoader turns out to be necessary
611- // or not, we fail fast if permission is not available.
612- sm .checkPermission (new RuntimePermission ("setContextClassLoader" ));
613- }
614584 this .task = task ;
615- this .acc = AccessController .getContext ();
616585 this .ccl = Thread .currentThread ().getContextClassLoader ();
617586 }
618587
619- @ SuppressWarnings ("removal" )
620588 public T call () throws Exception {
621- try {
622- return AccessController .doPrivileged (
623- new PrivilegedExceptionAction <T >() {
624- public T run () throws Exception {
625- Thread t = Thread .currentThread ();
626- ClassLoader cl = t .getContextClassLoader ();
627- if (ccl == cl ) {
628- return task .call ();
629- } else {
630- t .setContextClassLoader (ccl );
631- try {
632- return task .call ();
633- } finally {
634- t .setContextClassLoader (cl );
635- }
636- }
637- }
638- }, acc );
639- } catch (PrivilegedActionException e ) {
640- throw e .getException ();
589+ Thread t = Thread .currentThread ();
590+ ClassLoader cl = t .getContextClassLoader ();
591+ if (ccl == cl ) {
592+ return task .call ();
593+ } else {
594+ t .setContextClassLoader (ccl );
595+ try {
596+ return task .call ();
597+ } finally {
598+ t .setContextClassLoader (cl );
599+ }
641600 }
642601 }
643602
@@ -656,10 +615,7 @@ private static class DefaultThreadFactory implements ThreadFactory {
656615 private final String namePrefix ;
657616
658617 DefaultThreadFactory () {
659- @ SuppressWarnings ("removal" )
660- SecurityManager s = System .getSecurityManager ();
661- group = (s != null ) ? s .getThreadGroup () :
662- Thread .currentThread ().getThreadGroup ();
618+ group = Thread .currentThread ().getThreadGroup ();
663619 namePrefix = "pool-" +
664620 poolNumber .getAndIncrement () +
665621 "-thread-" ;
@@ -678,41 +634,23 @@ public Thread newThread(Runnable r) {
678634 }
679635
680636 /**
681- * Thread factory capturing access control context and class loader.
637+ * Thread factory capturing the current class loader.
682638 */
683639 private static class PrivilegedThreadFactory extends DefaultThreadFactory {
684640 @ SuppressWarnings ("removal" )
685- final AccessControlContext acc ;
686641 final ClassLoader ccl ;
687642
688- @ SuppressWarnings ("removal" )
689643 PrivilegedThreadFactory () {
690644 super ();
691- SecurityManager sm = System .getSecurityManager ();
692- if (sm != null ) {
693- // Calls to getContextClassLoader from this class
694- // never trigger a security check, but we check
695- // whether our callers have this permission anyways.
696- sm .checkPermission (SecurityConstants .GET_CLASSLOADER_PERMISSION );
697-
698- // Fail fast
699- sm .checkPermission (new RuntimePermission ("setContextClassLoader" ));
700- }
701- this .acc = AccessController .getContext ();
702645 this .ccl = Thread .currentThread ().getContextClassLoader ();
703646 }
704647
705648 public Thread newThread (final Runnable r ) {
706649 return super .newThread (new Runnable () {
707650 @ SuppressWarnings ("removal" )
708651 public void run () {
709- AccessController .doPrivileged (new PrivilegedAction <>() {
710- public Void run () {
711- Thread .currentThread ().setContextClassLoader (ccl );
712- r .run ();
713- return null ;
714- }
715- }, acc );
652+ Thread .currentThread ().setContextClassLoader (ccl );
653+ r .run ();
716654 }
717655 });
718656 }
@@ -811,9 +749,7 @@ private static class AutoShutdownDelegatedExecutorService
811749 super (executor );
812750 Runnable action = () -> {
813751 if (!executor .isShutdown ()) {
814- PrivilegedAction <Void > pa = () -> { executor .shutdown (); return null ; };
815- @ SuppressWarnings ("removal" )
816- var ignore = AccessController .doPrivileged (pa );
752+ executor .shutdown ();
817753 }
818754 };
819755 cleanable = CleanerFactory .cleaner ().register (this , action );
0 commit comments