Fix IllegalAccessException for JDK module classes in ClassRealm #134
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes an issue where JNDI and other JDK services fail with
IllegalAccessException
when running in Maven plugins with Java 9+.Problem
When using Maven plugins with Java 9+, code that uses JNDI (such as Netty's DNS resolver) fails with:
This occurs when:
The same code works fine when run as a regular Java application.
Root Cause
Java 9+ introduced module-aware class loading through
ClassLoader.findClass(String moduleName, String name)
. WhenmoduleName
is not null, it indicates the JVM is trying to find a class in a specific named module.The existing implementation simply returned
null
whenmoduleName != null
, which meant:Solution
Modified
ClassRealm.findClass(String moduleName, String name)
to properly delegate to the parent classloader (or system classloader as fallback) when a module name is specified. This ensures JDK module classes are loaded in the correct module context, allowing JNDI and other services to work properly.Testing
testLoadJdkModuleClassThroughJNDI()
test case that reproduces the exact scenario from the issue (Netty using JNDI in Maven plugins)Impact
findClass
methodFixes #XX
Original prompt
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.