Rule Set:
In attached project.
Description:
Upgraded to using PMD 5.6.1, now the following rules in our custom ruleset are failing the build with
java.lang.IllegalArgumentException: Unable to exclude rules [RuleNameGoesHere]; perhaps the rule name is mispelled?
Failing rules:
DataflowAnomalyAnalysis
ShortClassName
UselessParentheses
The rule names match up with latest PMD doc so they are not misspelled (ironically, the error message misspells the word misspelled). Why are these failing?
In addition, PMD should provide a list of all available rules (perhaps in INFO mode) instead of a pretty useless error message that leaves the user in the dark.
Code Sample demonstrating the issue:
Running PMD through: Gradle
Thanks for reporting this bug.
I'm not sure, what's happening here: When running your project with commandline PMD using the ruleset in src/main/resources/ruleset.xml, this problem doesn't occur.
I can reproduce the issue with your demo gradle project, though.
@adangel Thanks for looking into it. The Gradle guys tell me that they're just calling PMD, which is also indicated by the stacktrace.
Yes, the error is definitely coming from PMD. Gradle is calling PMD as an Ant task. However, calling PMD via Ant using the ruleset, also does not trigger the error... I'll keep investigating.
@adangel could you make any progress with this? Do you need any help?
Just some note for future: debugging gradle builds: GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000" ./gradlew --no-daemon check
So, the issue is about rule priorities: The gradle project defines the property rulePriority = 3 - which means, that all rules with a minimum priority of medium or higher should be executed. The rule DataflowAnomalyAnalysis has a priority of low (5) and is therefore not retrieved by the ruleset factory. Since it appeared now as if the rule couldn't be excluded (since it actually has not been excluded by the exclusion mechanism but by the priority selection), it's reported.
So, workaround is:
rulePriority property)We should definitely handle this case much better...
@adangel Thanks for getting to the bottom of this. Some comments:
On a related note, the compatibility ruleset factory is also triggering issues closely related to this:
For instance, having a ruleset defining:
<rule ref="rulesets/java/unusedcode.xml">
<exclude name="UnusedModifier" />
</rule>
would trigger the same error (java.lang.IllegalArgumentException: Unable to exclude rules [UnnecessaryModifier]; perhaps the rule name is mispelled?) since the rule was moved to the unnecessarycode ruleset.
This is also related to #393