RFR: 8362123: ClassLoader Leak via Executors.newSingleThreadExecutor(...)

Alan Bateman alanb at openjdk.org
Fri Sep 26 15:44:06 UTC 2025


On Mon, 14 Jul 2025 15:49:04 GMT, Chris Dennis <duke at openjdk.org> wrote:

> Executors shutdown via `shutdownNow()` should have their cleanables cleaned to prevent a classloader leak. This can happen if a classloader exists that both references the wrapped executor and is referenced by the delegate executor.
> 
> To quote @Martin-Buchholz:
>> BTW: I find Cleaners much harder to use than old finalize, and it looks like I'm not the only one!

test/jdk/java/util/concurrent/Executors/AutoShutdown.java line 134:

> 132:         Reference<?> reference = new PhantomReference(classLoader, queue);
> 133: 
> 134:         classLoader.loadClass("AutoShutdown$IsolatedClass").getDeclaredMethod("shutdown", Consumer.class).invoke(null, shutdown);

Can we split up and assert that the defining loader of IsolatedClass is "classLoader"?  It's important to be confident of that when looking at this test.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/26296#discussion_r2382772862


More information about the core-libs-dev mailing list