Repository navigation
[core] Fix #6913: Use the configured class loader in RuleSetLoader#loadFromString - #6921
Merged
adangel merged 2 commits intoAug 14, 2026
Merged
Conversation
…#loadFromString loadFromString wrapped the configured ResourceLoader in an anonymous subclass created with the no-arg constructor, so the wrapper fell back to PMD's own class loader. Resource lookups still worked because loadResourceAsStream delegates to the previous loader, but everything that goes through the class loader did not: loadRuleFromClassPath could not find rule classes that are only visible to the class loader passed to loadResourcesWith, and the ruleset failed to load with a ClassNotFoundException. Build the wrapper with the previous loader's class loader so class and classpath resource resolution keep using it.
Member
Contributor
|
Compared to main: (comment created at 2026-08-14 18:01:57+00:00 for 569e328) |
Member
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
RuleSetLoader#loadFromStringtemporarily replaces the configuredResourceLoaderwith an anonymous wrapper that serves the XML content for the symbolic file name. That wrapper was built with the no-argResourceLoader()constructor, so it silently fell back to PMD's own class loader.Resource lookups still behaved correctly, because the wrapper's
loadResourceAsStreamdelegates to the previous loader for every other name. Everything that goes through the class loader did not:ResourceLoader#loadRuleFromClassPathcould not find rule classes that are only visible to the class loader passed toloadResourcesWith(ClassLoader), so loading the ruleset failed withReflection error while instantiating rule (ClassNotFoundException).loadClassPathResourceAsStreamused the wrong class loader for the same reason.The fix constructs the wrapper with the previous loader's class loader, so class and classpath resource resolution keep using what the caller configured. Passing the class loader (rather than overriding the individual class-loading methods) also keeps any future
ResourceLoadermethod that uses the class loader correct by construction.ResourceLoader#getClassLoader()is added for that.ResourceLoaderlives innet.sourceforge.pmd.util.internaland is marked@internalApi, and japicmp reports no API change for this PR.Related issues
RuleSetLoader#loadFromStringignores previously configured Resource/ClassLoader #6913Ready?
Added unit tests for fixed bug/feature
RuleSetFactoryTest#testLoadFromStringUsesConfiguredClassLoaderloads a ruleset whoseclassattribute is only resolvable through the configured class loader. Onmainit fails withReflection error while instantiating rule (ClassNotFoundException); the other 59 tests of that class stay green, so the new test is not covered by the existing ones.Passing all unit tests
./mvnw -pl pmd-core verifyon this branch:Tests run: 6441, Failures: 0, Errors: 0, Skipped: 7, with checkstyle, pmd, cpd-check and japicmp all passing.Complete build
./mvnw clean verifypasses (checked automatically by github actions)GitHub Actions has not run on this PR yet, so I ran the complete build locally on
b141dac, with Temurin 21.0.9 on macOS aarch64:All 44 modules pass.
19188unit tests (Failures: 0, Errors: 0, Skipped: 39) plus31integration tests,checkstyle:checkreporting0violations in each of the 44 modules, andpmd:check,pmd:cpd-check,javadoc:jarandsource:jargreen everywhere.japicmp:cmpalso runs in all 44 modules and is configured withbreakBuildBasedOnSemanticVersioning, so the green build covers the API compatibility claim above.RuleSetFactoryTestitself runsTests run: 60, Failures: 0, Errors: 0, Skipped: 0, that is the 59 existing tests plus the new one.Added (in-code) documentation (if needed)