diff --git a/pmd-test/src/main/java/net/sourceforge/pmd/testframework/RuleTst.java b/pmd-test/src/main/java/net/sourceforge/pmd/testframework/RuleTst.java index 87e76589d0..7768660bd7 100644 --- a/pmd-test/src/main/java/net/sourceforge/pmd/testframework/RuleTst.java +++ b/pmd-test/src/main/java/net/sourceforge/pmd/testframework/RuleTst.java @@ -81,9 +81,8 @@ public abstract class RuleTst { public void runTest(TestDescriptor test) { Rule rule = test.getRule(); - if (test.getReinitializeRule()) { - rule = reinitializeRule(rule); - } + // always reinitialize the rule, regardless of test.getReinitializeRule() (#3976 / #3302) + rule = reinitializeRule(rule); Map, Object> oldProperties = rule.getPropertiesByPropertyDescriptor(); try { @@ -237,24 +236,9 @@ public abstract class RuleTst { PMDConfiguration configuration = new PMDConfiguration(); configuration.setDefaultLanguageVersion(languageVersion); configuration.setIgnoreIncrementalAnalysis(true); - if (isUseAuxClasspath) { - // configure the "auxclasspath" option for unit testing - configuration.prependAuxClasspath("."); - } else { - // simple class loader, that doesn't delegate to parent. - // this allows us in the tests to simulate PMD run without - // auxclasspath, not even the classes from the test dependencies - // will be found. - configuration.setClassLoader(new ClassLoader() { - @Override - protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { - if (name.startsWith("java.") || name.startsWith("javax.")) { - return super.loadClass(name, resolve); - } - throw new ClassNotFoundException(name); - } - }); - } + // regardless of isUseAuxClasspath the auxclasspath is always used (#3976 / #3302) + // configure the "auxclasspath" option for unit testing + configuration.prependAuxClasspath("."); RuleContext ctx = new RuleContext(); ctx.setReport(report); ctx.setSourceCodeFile(new File("n/a")); diff --git a/pmd-test/src/test/java/net/sourceforge/pmd/testframework/RuleTstTest.java b/pmd-test/src/test/java/net/sourceforge/pmd/testframework/RuleTstTest.java index 8ea4f81b75..f4b3c58610 100644 --- a/pmd-test/src/test/java/net/sourceforge/pmd/testframework/RuleTstTest.java +++ b/pmd-test/src/test/java/net/sourceforge/pmd/testframework/RuleTstTest.java @@ -36,6 +36,10 @@ public class RuleTstTest { private Rule rule = mock(Rule.class); private RuleTst ruleTester = new RuleTst() { + @Override + public Rule findRule(String ruleSet, String ruleName) { + return rule; + } }; @Test