-
Type:
Bug
-
Resolution: Fixed
-
Priority:
P4
-
Affects Version/s: 25
-
Component/s: core-libs
-
b22
-
generic
-
generic
| Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
|---|---|---|---|---|---|---|
| JDK-8371518 | 25.0.3-oracle | Johny Jose | P4 | Resolved | Fixed | master |
A DESCRIPTION OF THE PROBLEM :
Once the ContextClassLoader is changed on a thread in ForkJoinPool.commonPool() to a custom ClassLoader, it cannot be manually reset to the original value (ClassLoader.getSystemClassLoader()).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and start the supplied java program.
The program executes a task by using the ForkJoinPool.commonPool() which first changes the ContextClassLoader to a custom ClassLoader and then changes it back to the original ClassLoader.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The ContextClassCloader can be reset to its original value.
ACTUAL -
The ContextClassLoader remains the custom ClassLoader.
---------- BEGIN SOURCE ----------
public class ContextClassLoaderInForkJoinPoolCommonPool {
public static void main(String[] args) throws InterruptedException, ExecutionException {
CountDownLatch latch = new CountDownLatch(1);
ForkJoinPool.commonPool().execute(() -> {
Thread thread = Thread.currentThread();
ClassLoader originalCCL = thread.getContextClassLoader();
// Set a custom ContextClassLoader and verify that it has been set
ClassLoader customCCL = new URLClassLoader(new URL[0]);
thread.setContextClassLoader(customCCL);
if (thread.getContextClassLoader() != customCCL) {
throw new RuntimeException("ERROR: cannot set custom ContextClassLoader");
}
// Restore the original ContextClassLoader and verify that it has been set
thread.setContextClassLoader(originalCCL);
if (thread.getContextClassLoader() != originalCCL) {
throw new RuntimeException("ERROR: cannot reset to original ContextClassLoader");
}
latch.countDown();
});
latch.await();
}
}
---------- END SOURCE ----------
Once the ContextClassLoader is changed on a thread in ForkJoinPool.commonPool() to a custom ClassLoader, it cannot be manually reset to the original value (ClassLoader.getSystemClassLoader()).
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and start the supplied java program.
The program executes a task by using the ForkJoinPool.commonPool() which first changes the ContextClassLoader to a custom ClassLoader and then changes it back to the original ClassLoader.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The ContextClassCloader can be reset to its original value.
ACTUAL -
The ContextClassLoader remains the custom ClassLoader.
---------- BEGIN SOURCE ----------
public class ContextClassLoaderInForkJoinPoolCommonPool {
public static void main(String[] args) throws InterruptedException, ExecutionException {
CountDownLatch latch = new CountDownLatch(1);
ForkJoinPool.commonPool().execute(() -> {
Thread thread = Thread.currentThread();
ClassLoader originalCCL = thread.getContextClassLoader();
// Set a custom ContextClassLoader and verify that it has been set
ClassLoader customCCL = new URLClassLoader(new URL[0]);
thread.setContextClassLoader(customCCL);
if (thread.getContextClassLoader() != customCCL) {
throw new RuntimeException("ERROR: cannot set custom ContextClassLoader");
}
// Restore the original ContextClassLoader and verify that it has been set
thread.setContextClassLoader(originalCCL);
if (thread.getContextClassLoader() != originalCCL) {
throw new RuntimeException("ERROR: cannot reset to original ContextClassLoader");
}
latch.countDown();
});
latch.await();
}
}
---------- END SOURCE ----------
- backported by
-
JDK-8371518 ContextClassLoader cannot be reset on threads in ForkJoinPool.commonPool()
-
- Resolved
-
- links to
-
Commit(master)
openjdk/jdk/6f8d07ae
-
Review(master)
openjdk/jdk/27648