8328366: Thread.setContextClassloader from thread in FJP commonPool task no longer works after JDK-8327501

Reviewed-by: mchung, alanb
This commit is contained in:
Viktor Klang 2024-04-04 18:32:59 +00:00
parent 4276d5c004
commit 28216aa971
2 changed files with 9 additions and 6 deletions

View File

@ -1140,12 +1140,7 @@ public class ForkJoinPool extends AbstractExecutorService {
boolean isCommon = (pool.workerNamePrefix == null);
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
if (isCommon)
return new ForkJoinWorkerThread.InnocuousForkJoinWorkerThread(pool);
else
return new ForkJoinWorkerThread(null, pool, true, false);
} else if (isCommon)
if (sm != null && isCommon)
return newCommonWithACC(pool);
else
return newRegularWithACC(pool);

View File

@ -79,6 +79,9 @@ public class ForkJoinPool9Test extends JSR166TestCase {
assertSame(ForkJoinPool.commonPool(), ForkJoinTask.getPool());
Thread currentThread = Thread.currentThread();
ClassLoader preexistingContextClassLoader =
currentThread.getContextClassLoader();
Stream.of(systemClassLoader, null).forEach(cl -> {
if (randomBoolean())
// should always be permitted, without effect
@ -95,6 +98,11 @@ public class ForkJoinPool9Test extends JSR166TestCase {
() -> System.getProperty("foo"),
() -> currentThread.setContextClassLoader(
classLoaderDistinctFromSystemClassLoader));
else {
currentThread.setContextClassLoader(classLoaderDistinctFromSystemClassLoader);
assertSame(currentThread.getContextClassLoader(), classLoaderDistinctFromSystemClassLoader);
currentThread.setContextClassLoader(preexistingContextClassLoader);
}
// TODO ?
// if (haveSecurityManager
// && Thread.currentThread().getClass().getSimpleName()