GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [core] Fix #6913: Use the configured class loader in RuleSetLoader#loadFromString by renechoi · Pull Request #6921 · pmd/pmd

Conversation

@renechoi

@renechoi renechoi commented Jul 31, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Describe the PR

RuleSetLoader#loadFromString temporarily replaces the configured ResourceLoader with an anonymous wrapper that serves the XML content for the symbolic file name. That wrapper was built with the no-arg ResourceLoader() constructor, so it silently fell back to PMD's own class loader.

Resource lookups still behaved correctly, because the wrapper's loadResourceAsStream delegates to the previous loader for every other name. Everything that goes through the class loader did not:

  • ResourceLoader#loadRuleFromClassPath could not find rule classes that are only visible to the class loader passed to loadResourcesWith(ClassLoader), so loading the ruleset failed with Reflection error while instantiating rule (ClassNotFoundException).
  • loadClassPathResourceAsStream used the wrong class loader for the same reason.
new RuleSetLoader()
  .loadResourcesWith(customClassLoader)
  .loadFromString(location, rulesetXmlContent); // customClassLoader was ignored

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 ResourceLoader method that uses the class loader correct by construction.

ResourceLoader#getClassLoader() is added for that. ResourceLoader lives in net.sourceforge.pmd.util.internal and is marked @internalApi, and japicmp reports no API change for this PR.

Related issues

  • Fix [core] RuleSetLoader#loadFromString ignores previously configured Resource/ClassLoader #6913

Ready?

  • Added unit tests for fixed bug/feature

    RuleSetFactoryTest#testLoadFromStringUsesConfiguredClassLoader loads a ruleset whose class attribute is only resolvable through the configured class loader. On main it fails with Reflection 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 verify on this branch: Tests run: 6441, Failures: 0, Errors: 0, Skipped: 7, with checkstyle, pmd, cpd-check and japicmp all passing.

  • Complete build ./mvnw clean verify passes (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:

    ./mvnw --show-version --errors --batch-mode clean verify
    BUILD SUCCESS -- Total time: 12:33 min
    

    All 44 modules pass. 19188 unit tests (Failures: 0, Errors: 0, Skipped: 39) plus 31 integration tests, checkstyle:check reporting 0 violations in each of the 44 modules, and pmd:check, pmd:cpd-check, javadoc:jar and source:jar green everywhere. japicmp:cmp also runs in all 44 modules and is configured with breakBuildBasedOnSemanticVersioning, so the green build covers the API compatibility claim above. RuleSetFactoryTest itself runs Tests run: 60, Failures: 0, Errors: 0, Skipped: 0, that is the 59 existing tests plus the new one.

  • Added (in-code) documentation (if needed)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AB-xdev reacted with rocket emoji
All reactions
  • 🚀 1 reaction
@renechoi
[core] Fix pmd#6913: Use the configured class loader in RuleSetLoader…
b141dac
…#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.
@UncleOwen

UncleOwen commented Aug 7, 2026

Copy link
Copy Markdown
Member

@adangel Does this conflict with what you're doing in #6859?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pmd-actions-helper

pmd-actions-helper Bot commented Aug 7, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Documentation Preview

Compared to main:
This changeset changes 8 violations,
introduces 0 new violations, 0 new errors and 0 new configuration errors,
removes 0 violations, 0 errors and 0 configuration errors.
There are 0 changed duplications, 0 new duplications and 0 removed duplications.
There are 0 changed CPD errors, 0 new CPD errors and 0 removed CPD errors.

Regression Tester Report

(comment created at 2026-08-14 18:01:57+00:00 for 569e328)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel

adangel commented Aug 14, 2026

Copy link
Copy Markdown
Member

@adangel Does this conflict with what you're doing in #6859?

No, the resource loader is separate from the auxclasspath. The resource loader uses the runtime classpath to load rulesets and rules.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel
Merge branch 'main' into issue-6913-loadfromstring-classloader
569e328
@adangel adangel added this to the 7.27.0 milestone Aug 14, 2026
adangel
adangel approved these changes Aug 14, 2026
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@adangel
adangel merged commit eed52f5 into pmd:main Aug 14, 2026
13 checks passed

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@adangel adangel adangel approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

7.27.0

Development

Successfully merging this pull request may close these issues.

[core] RuleSetLoader#loadFromString ignores previously configured Resource/ClassLoader

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@renechoi @UncleOwen @adangel
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.