Fix ExtendedEnum ClassNotFoundException in ForkJoinPool (#2748)#2749
Fix ExtendedEnum ClassNotFoundException in ForkJoinPool (#2748)#2749oranoran wants to merge 1 commit intoOpenGamma:mainfrom
Conversation
Replace RenameHandler.lookupType() with Class.forName() using explicit classloader in ExtendedEnum and CombinedExtendedEnum. RenameHandler relies on thread context classloader which is null in ForkJoinPool workers, causing ClassNotFoundException in production environments with isolated classloader hierarchies (application servers, OSGi). The fix uses ExtendedEnum.class.getClassLoader() instead of TCCL, ensuring classes are loaded from the correct classloader regardless of threading context. Testing: - ExtendedEnumThreadSafetyTest: Verifies thread-safety patterns in various concurrent contexts (ForkJoinPool, parallel streams, CompletableFuture). This test is comprehensive and valuable, but it does not reproduce the bug, due to how classloading works under Surefire. - ExtendedEnumClassLoaderIsolationTest: Reproduces the production bug by running in an isolated parent/child classloader hierarchy with null TCCL, executed automatically during Maven verify phase, outside of the regular Maven/Surefire context.
|
I don't have access to see why the build has failed - can someone shed some light? |
|
Hello, Trying my luck here: Basically this PR is just fixing 2 lines of classloading code - the rest of the PR is just for testing the fix, simply because to reproduce the classloading issue the code needs to run outside of a testing framework. |
Replace RenameHandler.lookupType() with Class.forName() using explicit classloader in ExtendedEnum and CombinedExtendedEnum. RenameHandler relies on thread context classloader which is null in ForkJoinPool workers, causing ClassNotFoundException in production environments with isolated classloader hierarchies (application servers, OSGi).
The fix uses ExtendedEnum.class.getClassLoader() instead of TCCL, ensuring classes are loaded from the correct classloader regardless of threading context.
Testing: