2727
2828import java .lang .ref .Reference ;
2929import java .lang .reflect .Field ;
30- import java .security .AccessController ;
31- import java .security .AccessControlContext ;
32- import java .security .PrivilegedAction ;
3330import java .time .Duration ;
3431import java .util .Map ;
3532import java .util .HashMap ;
4138import jdk .internal .misc .TerminatingThreadLocal ;
4239import jdk .internal .misc .Unsafe ;
4340import jdk .internal .misc .VM ;
44- import jdk .internal .reflect .CallerSensitive ;
45- import jdk .internal .reflect .Reflection ;
4641import jdk .internal .vm .Continuation ;
4742import jdk .internal .vm .ScopedValueContainer ;
4843import jdk .internal .vm .StackableScope ;
5247import jdk .internal .vm .annotation .IntrinsicCandidate ;
5348import jdk .internal .vm .annotation .Stable ;
5449import sun .nio .ch .Interruptible ;
55- import sun .security .util .SecurityConstants ;
5650import static java .util .concurrent .TimeUnit .MILLISECONDS ;
5751import static java .util .concurrent .TimeUnit .NANOSECONDS ;
5852
@@ -652,21 +646,6 @@ static long next() {
652646 }
653647 }
654648
655- /**
656- * Returns the context class loader to inherit from the parent thread.
657- * See Thread initialization.
658- */
659- private static ClassLoader contextClassLoader (Thread parent ) {
660- @ SuppressWarnings ("removal" )
661- SecurityManager sm = System .getSecurityManager ();
662- if (sm == null || isCCLOverridden (parent .getClass ())) {
663- return parent .getContextClassLoader ();
664- } else {
665- // skip call to getContextClassLoader
666- return parent .contextClassLoader ;
667- }
668- }
669-
670649 /**
671650 * Initializes a platform Thread.
672651 *
@@ -676,11 +655,8 @@ private static ClassLoader contextClassLoader(Thread parent) {
676655 * @param task the object whose run() method gets called
677656 * @param stackSize the desired stack size for the new thread, or
678657 * zero to indicate that this parameter is to be ignored.
679- * @param acc ignored
680658 */
681- @ SuppressWarnings ("removal" )
682- Thread (ThreadGroup g , String name , int characteristics , Runnable task ,
683- long stackSize , AccessControlContext acc ) {
659+ Thread (ThreadGroup g , String name , int characteristics , Runnable task , long stackSize ) {
684660
685661 Thread parent = currentThread ();
686662 boolean attached = (parent == this ); // primordial or JNI attached
@@ -691,27 +667,10 @@ private static ClassLoader contextClassLoader(Thread parent) {
691667 }
692668 this .holder = new FieldHolder (g , task , stackSize , NORM_PRIORITY , false );
693669 } else {
694- SecurityManager sm = System .getSecurityManager ();
695670 if (g == null ) {
696- // the security manager can choose the thread group
697- if (sm != null ) {
698- g = sm .getThreadGroup ();
699- }
700-
701671 // default to current thread's group
702- if (g == null ) {
703- g = parent .getThreadGroup ();
704- }
672+ g = parent .getThreadGroup ();
705673 }
706-
707- // permission checks when creating a child Thread
708- if (sm != null ) {
709- sm .checkAccess (g );
710- if (isCCLOverridden (getClass ())) {
711- sm .checkPermission (SecurityConstants .SUBCLASS_IMPLEMENTATION_PERMISSION );
712- }
713- }
714-
715674 int priority = Math .min (parent .getPriority (), g .getMaxPriority ());
716675 this .holder = new FieldHolder (g , task , stackSize , priority , parent .isDaemon ());
717676 }
@@ -732,7 +691,7 @@ private static ClassLoader contextClassLoader(Thread parent) {
732691 this .inheritableThreadLocals = ThreadLocal .createInheritedMap (parentMap );
733692 }
734693 if (VM .isBooted ()) {
735- this .contextClassLoader = contextClassLoader ( parent );
694+ this .contextClassLoader = parent . getContextClassLoader ( );
736695 }
737696 } else if (VM .isBooted ()) {
738697 // default CCL to the system class loader when not inheriting
@@ -763,7 +722,7 @@ private static ClassLoader contextClassLoader(Thread parent) {
763722 if (parentMap != null && parentMap .size () > 0 ) {
764723 this .inheritableThreadLocals = ThreadLocal .createInheritedMap (parentMap );
765724 }
766- this .contextClassLoader = contextClassLoader ( parent );
725+ this .contextClassLoader = parent . getContextClassLoader ( );
767726 } else {
768727 // default CCL to the system class loader when not inheriting
769728 this .contextClassLoader = ClassLoader .getSystemClassLoader ();
@@ -1105,7 +1064,7 @@ private static String checkName(String name) {
11051064 * @see <a href="#inheritance">Inheritance when creating threads</a>
11061065 */
11071066 public Thread () {
1108- this (null , null , 0 , null , 0 , null );
1067+ this (null , null , 0 , null , 0 );
11091068 }
11101069
11111070 /**
@@ -1126,16 +1085,7 @@ public Thread() {
11261085 * @see <a href="#inheritance">Inheritance when creating threads</a>
11271086 */
11281087 public Thread (Runnable task ) {
1129- this (null , null , 0 , task , 0 , null );
1130- }
1131-
1132- /**
1133- * Creates a new Thread that inherits the given AccessControlContext
1134- * but thread-local variables are not inherited.
1135- * This is not a public constructor.
1136- */
1137- Thread (Runnable task , @ SuppressWarnings ("removal" ) AccessControlContext acc ) {
1138- this (null , null , 0 , task , 0 , acc );
1088+ this (null , null , 0 , task , 0 );
11391089 }
11401090
11411091 /**
@@ -1160,7 +1110,7 @@ public Thread(Runnable task) {
11601110 * @see <a href="#inheritance">Inheritance when creating threads</a>
11611111 */
11621112 public Thread (ThreadGroup group , Runnable task ) {
1163- this (group , null , 0 , task , 0 , null );
1113+ this (group , null , 0 , task , 0 );
11641114 }
11651115
11661116 /**
@@ -1177,7 +1127,7 @@ public Thread(ThreadGroup group, Runnable task) {
11771127 * @see <a href="#inheritance">Inheritance when creating threads</a>
11781128 */
11791129 public Thread (String name ) {
1180- this (null , checkName (name ), 0 , null , 0 , null );
1130+ this (null , checkName (name ), 0 , null , 0 );
11811131 }
11821132
11831133 /**
@@ -1198,7 +1148,7 @@ public Thread(String name) {
11981148 * @see <a href="#inheritance">Inheritance when creating threads</a>
11991149 */
12001150 public Thread (ThreadGroup group , String name ) {
1201- this (group , checkName (name ), 0 , null , 0 , null );
1151+ this (group , checkName (name ), 0 , null , 0 );
12021152 }
12031153
12041154 /**
@@ -1220,7 +1170,7 @@ public Thread(ThreadGroup group, String name) {
12201170 * @see <a href="#inheritance">Inheritance when creating threads</a>
12211171 */
12221172 public Thread (Runnable task , String name ) {
1223- this (null , checkName (name ), 0 , task , 0 , null );
1173+ this (null , checkName (name ), 0 , task , 0 );
12241174 }
12251175
12261176 /**
@@ -1256,7 +1206,7 @@ public Thread(Runnable task, String name) {
12561206 * @see <a href="#inheritance">Inheritance when creating threads</a>
12571207 */
12581208 public Thread (ThreadGroup group , Runnable task , String name ) {
1259- this (group , checkName (name ), 0 , task , 0 , null );
1209+ this (group , checkName (name ), 0 , task , 0 );
12601210 }
12611211
12621212 /**
@@ -1330,7 +1280,7 @@ public Thread(ThreadGroup group, Runnable task, String name) {
13301280 * @see <a href="#inheritance">Inheritance when creating threads</a>
13311281 */
13321282 public Thread (ThreadGroup group , Runnable task , String name , long stackSize ) {
1333- this (group , checkName (name ), 0 , task , stackSize , null );
1283+ this (group , checkName (name ), 0 , task , stackSize );
13341284 }
13351285
13361286 /**
@@ -1390,7 +1340,7 @@ public Thread(ThreadGroup group, Runnable task, String name,
13901340 long stackSize , boolean inheritInheritableThreadLocals ) {
13911341 this (group , checkName (name ),
13921342 (inheritInheritableThreadLocals ? 0 : NO_INHERIT_THREAD_LOCALS ),
1393- task , stackSize , null );
1343+ task , stackSize );
13941344 }
13951345
13961346 /**
@@ -2140,18 +2090,8 @@ public String toString() {
21402090 *
21412091 * @since 1.2
21422092 */
2143- @ CallerSensitive
21442093 public ClassLoader getContextClassLoader () {
2145- ClassLoader cl = this .contextClassLoader ;
2146- if (cl == null )
2147- return null ;
2148- @ SuppressWarnings ("removal" )
2149- SecurityManager sm = System .getSecurityManager ();
2150- if (sm != null ) {
2151- Class <?> caller = Reflection .getCallerClass ();
2152- ClassLoader .checkClassLoaderPermission (cl , caller );
2153- }
2154- return cl ;
2094+ return contextClassLoader ;
21552095 }
21562096
21572097 /**
@@ -2167,11 +2107,6 @@ public ClassLoader getContextClassLoader() {
21672107 * @since 1.2
21682108 */
21692109 public void setContextClassLoader (ClassLoader cl ) {
2170- @ SuppressWarnings ("removal" )
2171- SecurityManager sm = System .getSecurityManager ();
2172- if (sm != null ) {
2173- sm .checkPermission (new RuntimePermission ("setContextClassLoader" ));
2174- }
21752110 contextClassLoader = cl ;
21762111 }
21772112
@@ -2220,12 +2155,6 @@ public void setContextClassLoader(ClassLoader cl) {
22202155 */
22212156 public StackTraceElement [] getStackTrace () {
22222157 if (this != Thread .currentThread ()) {
2223- // check for getStackTrace permission
2224- @ SuppressWarnings ("removal" )
2225- SecurityManager security = System .getSecurityManager ();
2226- if (security != null ) {
2227- security .checkPermission (SecurityConstants .GET_STACK_TRACE_PERMISSION );
2228- }
22292158 // optimization so we do not call into the vm for threads that
22302159 // have not yet started or have terminated
22312160 if (!isAlive ()) {
@@ -2285,14 +2214,6 @@ StackTraceElement[] asyncGetStackTrace() {
22852214 * @since 1.5
22862215 */
22872216 public static Map <Thread , StackTraceElement []> getAllStackTraces () {
2288- // check for getStackTrace permission
2289- @ SuppressWarnings ("removal" )
2290- SecurityManager security = System .getSecurityManager ();
2291- if (security != null ) {
2292- security .checkPermission (SecurityConstants .GET_STACK_TRACE_PERMISSION );
2293- security .checkPermission (SecurityConstants .MODIFY_THREADGROUP_PERMISSION );
2294- }
2295-
22962217 // Get a snapshot of the list of all threads
22972218 Thread [] threads = getThreads ();
22982219 StackTraceElement [][] traces = dumpThreads (threads );
@@ -2307,64 +2228,6 @@ public static Map<Thread, StackTraceElement[]> getAllStackTraces() {
23072228 return m ;
23082229 }
23092230
2310- /** cache of subclass security audit results */
2311- private static class Caches {
2312- /** cache of subclass security audit results */
2313- static final ClassValue <Boolean > subclassAudits =
2314- new ClassValue <>() {
2315- @ Override
2316- protected Boolean computeValue (Class <?> type ) {
2317- return auditSubclass (type );
2318- }
2319- };
2320- }
2321-
2322- /**
2323- * Verifies that this (possibly subclass) instance can be constructed
2324- * without violating security constraints: the subclass must not override
2325- * security-sensitive non-final methods, or else the
2326- * "enableContextClassLoaderOverride" RuntimePermission is checked.
2327- */
2328- private static boolean isCCLOverridden (Class <?> cl ) {
2329- if (cl == Thread .class )
2330- return false ;
2331-
2332- return Caches .subclassAudits .get (cl );
2333- }
2334-
2335- /**
2336- * Performs reflective checks on given subclass to verify that it doesn't
2337- * override security-sensitive non-final methods. Returns true if the
2338- * subclass overrides any of the methods, false otherwise.
2339- */
2340- private static boolean auditSubclass (final Class <?> subcl ) {
2341- @ SuppressWarnings ("removal" )
2342- Boolean result = AccessController .doPrivileged (
2343- new PrivilegedAction <>() {
2344- public Boolean run () {
2345- for (Class <?> cl = subcl ;
2346- cl != Thread .class ;
2347- cl = cl .getSuperclass ())
2348- {
2349- try {
2350- cl .getDeclaredMethod ("getContextClassLoader" , new Class <?>[0 ]);
2351- return Boolean .TRUE ;
2352- } catch (NoSuchMethodException ex ) {
2353- }
2354- try {
2355- Class <?>[] params = {ClassLoader .class };
2356- cl .getDeclaredMethod ("setContextClassLoader" , params );
2357- return Boolean .TRUE ;
2358- } catch (NoSuchMethodException ex ) {
2359- }
2360- }
2361- return Boolean .FALSE ;
2362- }
2363- }
2364- );
2365- return result .booleanValue ();
2366- }
2367-
23682231 /**
23692232 * Return an array of all live threads.
23702233 */
@@ -2603,12 +2466,6 @@ public interface UncaughtExceptionHandler {
26032466 * @since 1.5
26042467 */
26052468 public static void setDefaultUncaughtExceptionHandler (UncaughtExceptionHandler ueh ) {
2606- @ SuppressWarnings ("removal" )
2607- SecurityManager sm = System .getSecurityManager ();
2608- if (sm != null ) {
2609- sm .checkPermission (
2610- new RuntimePermission ("setDefaultUncaughtExceptionHandler" ));
2611- }
26122469 defaultUncaughtExceptionHandler = ueh ;
26132470 }
26142471
@@ -2675,7 +2532,6 @@ void dispatchUncaughtException(Throwable e) {
26752532 /**
26762533 * Holder class for constants.
26772534 */
2678- @ SuppressWarnings ("removal" )
26792535 private static class Constants {
26802536 // Thread group for virtual threads.
26812537 static final ThreadGroup VTHREAD_GROUP ;
0 commit comments