Skip to content

Conversation

@oranoran
Copy link

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.

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.
@oranoran
Copy link
Author

I don't have access to see why the build has failed - can someone shed some light?
Locally on my Mac, "mvn clean install" passes, including the new tests.
I hope there is no issue in CircleCI with the exec-maven-plugin running a standalone Java process for the ExtendedEnum classloader isolation test. If there is - this can be dropped from the POM, losing the regression test as part of the CI build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant