Skip to content

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

Closed

Description

@AB-xdev

Affects PMD Version:

7.26.0 (latest)

Description:

When loading a Ruleset using RuleSetLoader#loadFromString the method completely ignores the previously set ResouceLoader (which also contains the classloader) and uses it's own ResourceLoader:

public RuleSet loadFromString(String filename, final String rulesetXmlContent) {
if (filename == null || filename.isEmpty()) {
throw new IllegalArgumentException("Invalid empty filename");
}
ResourceLoader oldLoader = this.resourceLoader;
try {
loadResourcesWith(new ResourceLoader() {
@Override
public @NonNull InputStream loadResourceAsStream(String name) throws IOException {
if (Objects.equals(name, filename)) {
return new ByteArrayInputStream(rulesetXmlContent.getBytes(StandardCharsets.UTF_8));
}
return oldLoader.loadResourceAsStream(name);
}
});
return loadFromResource(new RuleSetReferenceId(filename, null));
} finally {
loadResourcesWith(oldLoader);
}
}

In my case this ResourceLoader lacks certain classes and resources and therefore causes a subsequent crash.

Exception Stacktrace:

N/A

Code Sample demonstrating the issue:

new RuleSetLoader()
  .loadResourcesWith(customClassLoader)
  .loadFromString(this.getLocation(), rulesetXmlContent); // Ignores customClassLoader

Steps to reproduce:

See code above

Running PMD through: Other

Activity

  1. added
    a:bug
    on Jul 29, 2026
  2. added this to the 7.27.0 milestone on Aug 14, 2026
  3. added a commit that references this issue on Aug 14, 2026
    eed52f5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions