Skip to content

Commit

Permalink
8328366: Thread.setContextClassloader from thread in FJP commonPool t…
Browse files Browse the repository at this point in the history
…ask no longer works after JDK-8327501

Reviewed-by: mchung, alanb
  • Loading branch information
Viktor Klang committed Apr 4, 2024
1 parent 4276d5c commit 28216aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1140,12 +1140,7 @@ public final ForkJoinWorkerThread newThread(ForkJoinPool pool) {
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);
Expand Down
8 changes: 8 additions & 0 deletions test/jdk/java/util/concurrent/tck/ForkJoinPool9Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public void testCommonPoolThreadContextClassLoader() throws Throwable {
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
Expand All @@ -95,6 +98,11 @@ public void testCommonPoolThreadContextClassLoader() throws Throwable {
() -> System.getProperty("foo"),
() -> currentThread.setContextClassLoader(
classLoaderDistinctFromSystemClassLoader));
else {
currentThread.setContextClassLoader(classLoaderDistinctFromSystemClassLoader);
assertSame(currentThread.getContextClassLoader(), classLoaderDistinctFromSystemClassLoader);
currentThread.setContextClassLoader(preexistingContextClassLoader);
}
// TODO ?
// if (haveSecurityManager
// && Thread.currentThread().getClass().getSimpleName()
Expand Down

1 comment on commit 28216aa

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.