Add Java Class File API support for module-info parsing (Java 24+) #211
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.
Overview
This PR implements support for the Java Class File API (JEP 484) to parse
module-info.class
files, as requested in the issue. The Class File API provides a native JDK alternative to ASM for class file parsing and is the preferred approach for Java 24 and later.Implementation
Added a new
src/main/java24
directory containing:ClassFileApiModuleInfoParser
- Core parser implementation using the nativejava.lang.classfile
APIBinaryModuleInfoParser
- Override that delegates to the Class File API parserThe implementation follows the existing multi-release JAR pattern:
java.lang.module.ModuleDescriptor
APIThe JVM automatically selects the appropriate implementation at runtime based on the Java version.
Build Configuration
Added Maven profile to handle Java 24+:
jdk24
profile (Java 24+): Compiles with release 24 using the finalized Class File APIThe profile compiles the
java24
sources and outputs toMETA-INF/versions/24
in the multi-release JAR.Benefits
Testing
All existing tests pass (78 unit tests + 4 integration tests). The implementation will be automatically tested when built and run with Java 24+ due to the multi-release JAR mechanism. No new tests were required as
BinaryModuleInfoParserTest
already covers all parsing scenarios.Compatibility
Notes
This implementation uses the finalized Class File API in Java 24 (JEP 484), avoiding preview feature issues that would exist with Java 22-23. Users on Java versions before 24 continue to use the existing implementations (Java 9-23 uses
ModuleDescriptor
, Java 8 uses ASM) without any impact.Closes #165
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.