Affects PMD Version:
7.0.0
Description:
If a top level rule-set XML file contains a reference to another rule-set XML file, the referenced (AKA child) file will never emit an error message when validation fails, making it impossible to troubleshoot.
Referencing the ruleset directly however will work as expected.
Exception Stacktrace:
net.sourceforge.pmd.lang.rule.RuleSetLoadException: Cannot load ruleset ./submodules/framework/pmd/rulesets/apex/unit-testing.xml: An XML validation error occurred
at net.sourceforge.pmd.lang.rule.RuleSetFactory.readDocument(RuleSetFactory.java:196)
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.RuleSetLoader.loadRuleSetsWithoutException(RuleSetLoader.java:202)
at net.sourceforge.pmd.lang.rule.InternalApiBridge.loadRuleSetsWithoutException(InternalApiBridge.java:40)
at net.sourceforge.pmd.PmdAnalysis.create(PmdAnalysis.java:199)
at net.sourceforge.pmd.cli.commands.internal.PmdCommand.doExecute(PmdCommand.java:311)
at net.sourceforge.pmd.cli.commands.internal.PmdCommand.doExecute(PmdCommand.java:48)
at net.sourceforge.pmd.cli.internal.PmdRootLogger.executeInLoggingContext(PmdRootLogger.java:55)
at net.sourceforge.pmd.cli.commands.internal.AbstractAnalysisPmdSubcommand.execute(AbstractAnalysisPmdSubcommand.java:111)
at net.sourceforge.pmd.cli.commands.internal.AbstractPmdSubcommand.call(AbstractPmdSubcommand.java:30)
at net.sourceforge.pmd.cli.commands.internal.AbstractPmdSubcommand.call(AbstractPmdSubcommand.java:16)
at picocli.CommandLine.executeUserObject(CommandLine.java:2041)
at picocli.CommandLine.access$1500(CommandLine.java:148)
at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2461)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2453)
at picocli.CommandLine$RunLast.handle(CommandLine.java:2415)
at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2273)
at picocli.CommandLine$RunLast.execute(CommandLine.java:2417)
at picocli.CommandLine.execute(CommandLine.java:2170)
at net.sourceforge.pmd.cli.PmdCli.main(PmdCli.java:24)
Code Sample demonstrating the issue:
<?xml version="1.0" encoding="UTF-8"?> <ruleset name="parent" 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>Parent that includes a child.</description> <rule ref="child.xml" /> </ruleset>
<?xml version="1.0" encoding="UTF-8"?> <ruleset name="child" 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>Child.</description> <rule name="ApexUnitTestsMethodsShouldHaveAsserts" language="apex" message="Child message" class="net.sourceforge.pmd.lang.rule.XPathRule"> <description> Update to the standard "Apex Unit Test must have assertions" that includes checking for Ortoo specific assertion methods and the use of Amoss verify methods. </description> <priority>1</priority> <properties> <property name="version" value="2.0"/> <property name="xpath"> <value> <![CDATA[ //Method[ModifierNode/Annotation[lower-case(@Image)='istest']] [ not( .//MethodCallExpression[lower-case(@MethodName)=('assertequals','assertnotequals','assert')][ReferenceExpression[lower-case(@Image)='system']] or .//MethodCallExpression[ReferenceExpression/lower-case(@Image)=('assert')] or .//MethodCallExpression[lower-case(@MethodName)='verify']) ] ]]> </value> </property> </properties> </rule> </ruleset>
Steps to reproduce:
Please provide detailed steps for how we can reproduce the bug.
Running PMD through: [Other]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4