Repository navigation
Description
Affects PMD Version: 7.25.0 (any version; the message is unchanged in current main)
Description:
When a ruleset references a standard rule that does not exist in the running PMD (typically because the rule was added in a newer release), the loader fails with:
Unable to find referenced rule InvocableClassNoArgConstructor; perhaps the rule name is misspelled?
The "misspelled" hint is the only diagnosis offered, but in practice the commonest cause is a version gap, not a typo. This is easy to hit without ever choosing a PMD version yourself: several ecosystem tools bundle their own PMD (for example Salesforce Code Analyzer currently embeds pmd-apex 7.25.0), so a ruleset written against current PMD docs fails inside the tool with a message that sends the author hunting for a spelling error.
That this recurs is visible in this tracker: #4737 is the same situation (a ruleset referencing category/apex/performance.xml/OperationWithHighCostInLoop on a PMD that predated the rule), reported as a bug and closed once a maintainer explained the version gap by hand. A version-aware message would have answered it without a round-trip.
Proposed behaviour:
Include the running PMD version, and where applicable the resolved category file, in the error:
Unable to find rule 'InvocableClassNoArgConstructor' in category/apex/errorprone.xml (PMD 7.25.0).
Check the spelling, or whether the rule was added in a newer PMD release than the one running.
The failure itself staying fatal for the whole ruleset seems right (silently running fewer rules than configured would be worse for an analysis gate); this request is only about making the message name the actual likely cause.
Possible extension (separate decision): an opt-in loader flag that skips unresolvable references with a prominent warning instead of failing the ruleset, for consumers who prefer degraded operation over none. Not requested as a default.
Code context: the message originates in the ruleset factory's rule-reference resolution (RuleSetFactory / RuleSetLoader path that emits "perhaps the rule name is misspelled?"). PMDVersion.VERSION is available to the same classpath.
Steps to reproduce (any PMD version):
- Create
repro-rules.xmlreferencing a rule name that does not exist:
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="Repro"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>repro</description>
<rule ref="category/apex/errorprone.xml/RuleThatDoesNotExist"/>
</ruleset>- Run it against any Apex file:
pmd check -d SomeClass.cls -R repro-rules.xml -f text --no-cache
Output on PMD 7.26.0 (verified):
<rule ref="category/apex/errorprone.xml/RuleThatDoesNotExist"/>
^^^^^ Unable to find referenced rule RuleThatDoesNotExist; perhaps the rule name is misspelled?
No PMD version appears anywhere in the error, so a reader cannot tell a typo from a version gap without external digging.
Activity
friskychicken commentedon Jul 12, 2026
For context, the ecosystem case that motivated this: forcedotcom/code-analyzer#2065 (Code Analyzer bundles pmd-apex 7.25.0 with no override path, so rulesets referencing 7.26.0 rules fail inside it with the misspelling hint).