Repository navigation
Closed
Description
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:
pmd/pmd-core/src/main/java/net/sourceforge/pmd/lang/rule/RuleSetLoader.java
Lines 150 to 170 in 1ac594b
| 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 customClassLoaderSteps to reproduce:
See code above
Running PMD through: Other
Activity
[core] Fix pmd#6913: Use the configured class loader in RuleSetLoader…