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] Ruleset references that are relative to another ruleset cannot be resolved · Issue #6952 · pmd/pmd

[core] Ruleset references that are relative to another ruleset cannot be resolved #6952

New issue
Copy link
New issue
Copy link
Closed
#6953
Closed
[core] Ruleset references that are relative to another ruleset cannot be resolved#6952
#6953
Copy link
Assignees
lukasgraef
Labels
a:bugPMD crashes or fails to analyse a file.
Milestone
7.27.0

Description

@lukasgraef
lukasgraef
opened on Aug 6, 2026
Issue body actions

Affects PMD Version:

7.26

Description:

PMD's RuleSetLoader can't resolve rule file references, if both these conditions are met:

  • the referenced file is not on the classpath
  • the referenced file's relative path cannot be resolved from the working dir

Consequence: Rule file references that are relative to the rule file from which they're referenced from cannot be resolved.
This mostly happens due to Gradle's usage of PMD (absolute path to main ruleset, running from another workdir), I still think it would be sensible to also resolve sibling rulesets.

This causes the bug described in gradle/gradle#24885.

Exception Stacktrace:

From the testcase below:

net.sourceforge.pmd.lang.rule.RuleSetLoadException: Cannot load ruleset base.xml: Cannot resolve rule/ruleset reference 'base.xml'.  Make sure the resource is a valid file or URL and is on the CLASSPATH. Use --debug (or a fine log level) to see the current classpath.

	at net.sourceforge.pmd.lang.rule.RuleSetFactory.readDocument(RuleSetFactory.java:203)
	at net.sourceforge.pmd.lang.rule.RuleSetFactory.createRuleSet(RuleSetFactory.java:119)
	at net.sourceforge.pmd.lang.rule.RuleSetFactory.createRuleSet(RuleSetFactory.java:114)
	at net.sourceforge.pmd.lang.rule.RuleSetFactory.parseRuleSetReferenceNode(RuleSetFactory.java:389)
	at net.sourceforge.pmd.lang.rule.RuleSetFactory.parseRuleNode(RuleSetFactory.java:335)
	at net.sourceforge.pmd.lang.rule.RuleSetFactory.parseRulesetNode(RuleSetFactory.java:242)
	at net.sourceforge.pmd.lang.rule.RuleSetFactory.readDocument(RuleSetFactory.java:186)
	at net.sourceforge.pmd.lang.rule.RuleSetFactory.createRuleSet(RuleSetFactory.java:119)
	at net.sourceforge.pmd.lang.rule.RuleSetFactory.createRuleSet(RuleSetFactory.java:114)
	at net.sourceforge.pmd.lang.rule.RuleSetLoader.loadFromResource(RuleSetLoader.java:248)
	at net.sourceforge.pmd.lang.rule.RuleSetLoader.loadFromResource(RuleSetLoader.java:139)
	at net.sourceforge.pmd.lang.rule.RuleSetFactoryTest.testRefToSiblingRuleset(RuleSetFactoryTest.java:62)
Caused by: java.io.FileNotFoundException: Cannot resolve rule/ruleset reference 'base.xml'.  Make sure the resource is a valid file or URL and is on the CLASSPATH. Use --debug (or a fine log level) to see the current classpath.
	at net.sourceforge.pmd.lang.rule.internal.RuleSetReferenceId.notFoundException(RuleSetReferenceId.java:309)
	at net.sourceforge.pmd.lang.rule.internal.RuleSetReferenceId.getInputStream(RuleSetReferenceId.java:304)
	at net.sourceforge.pmd.lang.rule.RuleSetFactory.readDocument(RuleSetFactory.java:165)

Code Sample demonstrating the issue:

Add the following to net.sourceforge.pmd.lang.rule.RuleSetFactoryTest:

@Test
void testRefToSiblingRuleset(@TempDir Path tempDir) throws IOException {
    write(tempDir.resolve("leaf.xml"), rulesetXml(dummyRule()));
    write(tempDir.resolve("base.xml"), rulesetXml(rulesetRef("leaf.xml")));
    write(tempDir.resolve("main.xml"), rulesetXml(rulesetRef("base.xml")));

    RuleSet rs = new RuleSetLoader().loadFromResource(tempDir.resolve("main.xml").toString());
    assertEquals(1, rs.size());
    assertNotNull(rs.getRuleByName("MockRuleName"));
}

private static void write(Path file, String content) throws IOException {
    Files.write(file, content.getBytes(StandardCharsets.UTF_8));
}

Steps to reproduce:

Run the (failing) test pasted above.

Alternatively, try the setup linked in the Gradle issue: https://github.com/lukelukes/gradle-pmd-bug

Running PMD through: Gradle

Activity

  1. lukasgraef
    self-assigned this
    on Aug 6, 2026
  2. lukasgraef
    added
    a:bugPMD crashes or fails to analyse a file.
    on Aug 6, 2026
  3. lukasgraef
    added a commit that references this issue on Aug 7, 2026

    [core] Fix pmd#6952: Resolve ruleset references relative to the refer…

    This issue will close once commit fe18b90 is merged into the 'master' branch.
    fe18b90
  4. UncleOwen
    added this to the 7.27.0 milestone on Aug 11, 2026
  5. UncleOwen
    added a commit that references this issue on Aug 11, 2026

    [core] Fix #6952: Resolve ruleset references relative to the referenc…

    This issue will close once commit 3db1fe0 is merged into the 'main' branch.
    3db1fe0
  6. UncleOwen
    closed this as completedin #6953on Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @lukasgraef
    lukasgraef

Labels

a:bugPMD crashes or fails to analyse a file.

Type

No type

Projects

No projects

    Milestone

    • 7.27.0

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    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.