Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -981,9 +981,7 @@ public final ForkJoinWorkerThread newThread(ForkJoinPool pool) {
boolean isCommon = (pool.workerNamePrefix == null);
@SuppressWarnings("removal")
SecurityManager sm = System.getSecurityManager();
if (sm == null)
return new ForkJoinWorkerThread(null, pool, true, false);
else if (isCommon)
if (sm != null && isCommon)
Copy link
Contributor

Choose a reason for hiding this comment

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

The check should be if (isCommon && JLA.allowSecurityManager()) as a SM can be set mid-flight even if it is super weird to do that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is what the backport of JDK-8342905 will do which Martin mentioned he'll do as a follow-up after this one.

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