[java] Support loading classes from java runtime images#4628
Merged
adangel merged 13 commits intopmd:masterfrom Jan 5, 2024
Merged
[java] Support loading classes from java runtime images#4628adangel merged 13 commits intopmd:masterfrom
adangel merged 13 commits intopmd:masterfrom
Conversation
That's one missing piece to support running PMD on a different JRE than the one used for analyzing. For Java up to version 8, one can put lib/rt.jar on the auxclasspath. But since Java 9, the runtime classes are stored in runtime images, that need to be loaded through the jrt:/ file system. Since the jrt-URLs are not connected anymore to a specific runtime image, AsmSymbolResolver needs to use directly the streams instead of URLs. The ClasspathClassLoader is basically disabled to actually load classes for reflection (#loadClass). In PMD 7, we shouldn't use that anymore. See also https://openjdk.org/jeps/220
Generated by 🚫 Danger |
oowekyala
reviewed
Jul 7, 2023
Member
oowekyala
left a comment
There was a problem hiding this comment.
Very nice! I didn't know about this jrt file system
pmd-core/src/main/java/net/sourceforge/pmd/internal/util/ClasspathClassLoader.java
Outdated
Show resolved
Hide resolved
...java/src/main/java/net/sourceforge/pmd/lang/java/symbols/internal/asm/AsmSymbolResolver.java
Show resolved
Hide resolved
This was referenced Oct 26, 2023
Co-authored-by: Clément Fournier <clement.fournier@tu-dresden.de>
This includes some stats in AsmSymbolResolver. Co-authored-by: Clément Fournier <clement.fournier@tu-dresden.de>
This makes it probably a bit faster and doesn't leave an open groovy jar file behind.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Describe the PR
That's one missing piece to support running PMD on a different JRE
than the one used for analyzing. For Java up to version 8, one can put
jre/lib/rt.jar on the auxclasspath. But since Java 9, the runtime classes
are stored in runtime images (e.g. jmods/java.base.jmod...), that need to be loaded through the
jrt:/ file system.
Since the jrt-URLs are not connected anymore to a specific runtime
image, AsmSymbolResolver needs to use directly the streams instead
of URLs.
The ClasspathClassLoader is basically disabled to actually load
classes for reflection (#loadClass). In PMD 7, we shouldn't use that
anymore.
See also https://openjdk.org/jeps/220
I've orientated myself by https://github.com/spotbugs/spotbugs/blob/master/spotbugs/src/main/java/edu/umd/cs/findbugs/classfile/impl/JrtfsCodeBase.java and chose to also create a map for packages to modules. In java 17, there are 70 modules. So this hopefully helps a bit for performance when looking up classes.
Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)