From 54ce3036b2b4faa8edff04838844c9303bd525df Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 10 Mar 2016 20:01:59 +0100 Subject: [PATCH 1/4] Add unit test to verify concurrency issue #1461 References pr #75 --- .../processor/MultiThreadProcessorTest.java | 109 ++++++++++++++++++ .../MultiThreadProcessorTest/basic.xml | 15 +++ 2 files changed, 124 insertions(+) create mode 100644 pmd-core/src/test/java/net/sourceforge/pmd/processor/MultiThreadProcessorTest.java create mode 100644 pmd-core/src/test/resources/rulesets/MultiThreadProcessorTest/basic.xml diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/processor/MultiThreadProcessorTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/processor/MultiThreadProcessorTest.java new file mode 100644 index 0000000000..3aa643821b --- /dev/null +++ b/pmd-core/src/test/java/net/sourceforge/pmd/processor/MultiThreadProcessorTest.java @@ -0,0 +1,109 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ +package net.sourceforge.pmd.processor; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +import org.junit.Assert; +import org.junit.Test; + +import net.sourceforge.pmd.PMDConfiguration; +import net.sourceforge.pmd.ReportListener; +import net.sourceforge.pmd.RuleContext; +import net.sourceforge.pmd.RuleSetFactory; +import net.sourceforge.pmd.RuleViolation; +import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.rule.AbstractRule; +import net.sourceforge.pmd.renderers.Renderer; +import net.sourceforge.pmd.stat.Metric; +import net.sourceforge.pmd.util.datasource.DataSource; + +public class MultiThreadProcessorTest { + + @Test + public void testRulesThreadSafety() { + PMDConfiguration configuration = new PMDConfiguration(); + configuration.setRuleSets("rulesets/MultiThreadProcessorTest/basic.xml"); + configuration.setThreads(2); + List files = new ArrayList<>(); + files.add(new StringDataSource("file1-violation.dummy", "ABC")); + files.add(new StringDataSource("file2-foo.dummy", "DEF")); + + SimpleReportListener reportListener = new SimpleReportListener(); + RuleContext ctx = new RuleContext(); + ctx.getReport().addListener(reportListener); + + MultiThreadProcessor processor = new MultiThreadProcessor(configuration); + RuleSetFactory ruleSetFactory = new RuleSetFactory(); + processor.processFiles(ruleSetFactory, files, ctx, Collections.emptyList()); + + // if the rule is not executed, then maybe a ConcurrentModificationException happened + Assert.assertEquals("Test rule has not been executed", 2, NotThreadSafeRule.count.get()); + // if the violation is not reported, then the rule instances have been shared between the threads + Assert.assertEquals("Missing violation", 1, reportListener.violations.get()); + } + + private static class StringDataSource implements DataSource { + private final String data; + private final String name; + public StringDataSource(String name, String data) { + this.name = name; + this.data = data; + } + @Override + public InputStream getInputStream() throws IOException { + return new ByteArrayInputStream(data.getBytes("UTF-8")); + } + @Override + public String getNiceFileName(boolean shortNames, String inputFileName) { + return name; + } + } + + public static class NotThreadSafeRule extends AbstractRule { + public static AtomicInteger count = new AtomicInteger(0); + private boolean hasViolation; // this variable will be overridden between the threads + @Override + public void apply(List nodes, RuleContext ctx) { + count.incrementAndGet(); + + if (ctx.getSourceCodeFilename().contains("violation")) { + hasViolation = true; + } else { + letTheOtherThreadRun(10); + hasViolation = false; + } + + letTheOtherThreadRun(100); + if (hasViolation) { + addViolation(ctx, nodes.get(0)); + } + } + private void letTheOtherThreadRun(int millis) { + try { + Thread.yield(); + Thread.sleep(millis); + } catch (InterruptedException e) { + // ignored + } + } + } + + private static class SimpleReportListener implements ReportListener { + public AtomicInteger violations = new AtomicInteger(0); + @Override + public void ruleViolationAdded(RuleViolation ruleViolation) { + violations.incrementAndGet(); + } + @Override + public void metricAdded(Metric metric) { + } + } +} diff --git a/pmd-core/src/test/resources/rulesets/MultiThreadProcessorTest/basic.xml b/pmd-core/src/test/resources/rulesets/MultiThreadProcessorTest/basic.xml new file mode 100644 index 0000000000..499b6a4596 --- /dev/null +++ b/pmd-core/src/test/resources/rulesets/MultiThreadProcessorTest/basic.xml @@ -0,0 +1,15 @@ + + + + + Ruleset used by test RuleSetReferenceIdTest + + + + Foo + 3 + + + \ No newline at end of file From 3de70426cf458294940fa0afb293d6de1cda960e Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 10 Mar 2016 20:06:53 +0100 Subject: [PATCH 2/4] Revert "Update changelog, keep backwards compatible createRuleSets methods by overloading" This reverts commit b753cc5ec5d2240e907b60f78925f78c2f682bf5. --- .../net/sourceforge/pmd/PMDConfiguration.java | 28 ++++++++-------- .../net/sourceforge/pmd/RuleSetFactory.java | 22 ++----------- .../sourceforge/pmd/RulesetsFactoryUtils.java | 32 ++----------------- .../sourceforge/pmd/RuleSetFactoryTest.java | 2 +- .../pmd/testframework/RuleTst.java | 2 +- 5 files changed, 21 insertions(+), 65 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java index f0a63b4518..8c1113bb82 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java @@ -271,22 +271,22 @@ public class PMDConfiguration extends AbstractConfiguration { /** * Get the RuleSets. * - * @return the pmdRuleSets - */ - public RuleSets getPmdRuleSets() { - return pmdRuleSets; - } + * @return the pmdRuleSets + */ + public RuleSets getPmdRuleSets() { + return pmdRuleSets; + } - /** - * Set the RuleSets - * - * @param pmdRuleSets the pmdRuleSets to set - */ - public void setPmdRuleSets(RuleSets pmdRuleSets) { - this.pmdRuleSets = pmdRuleSets; - } + /** + * Set the RuleSets + * + * @param pmdRuleSets the pmdRuleSets to set + */ + public void setPmdRuleSets(RuleSets pmdRuleSets) { + this.pmdRuleSets = pmdRuleSets; + } - /** + /** * Get the minimum priority threshold when loading Rules from RuleSets. * * @return The minimum priority threshold. diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java index a627fc4f01..e4f93d0693 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java @@ -104,21 +104,6 @@ public class RuleSetFactory { } } - /** - * Create a RuleSets from a comma separated list of RuleSet reference IDs - * when the parameter ruleSets is null. This is a convenience method which - * calls {@link RuleSetReferenceId#parse(String)}, and then calls - * {@link #createRuleSets(List)}. The currently configured ClassLoader is - * used. - * - * @param referenceString A comma separated list of RuleSet reference IDs. - * @return The new RuleSets. - * @throws RuleSetNotFoundException if unable to find a resource. - */ - public synchronized RuleSets createRuleSets(String referenceString) throws RuleSetNotFoundException { - return createRuleSets(referenceString, null); - } - /** * Create a RuleSets from a comma separated list of RuleSet reference IDs when the parameter ruleSets is null. * This is a convenience method which calls @@ -128,13 +113,12 @@ public class RuleSetFactory { * * @param referenceString A comma separated list of RuleSet reference IDs. * @param ruleSets RuleSets initialized in PMDConfiguration. - * @return The new RuleSets or the rulesets from PMDConfiguration if not null + * @return The new RuleSets. * @throws RuleSetNotFoundException if unable to find a resource. */ public synchronized RuleSets createRuleSets(String referenceString, RuleSets ruleSets) throws RuleSetNotFoundException { - if (ruleSets != null) { - return ruleSets; - } + if(ruleSets != null) + return ruleSets; return createRuleSets(RuleSetReferenceId.parse(referenceString)); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RulesetsFactoryUtils.java b/pmd-core/src/main/java/net/sourceforge/pmd/RulesetsFactoryUtils.java index 76fab7d7eb..0e5d668454 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RulesetsFactoryUtils.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RulesetsFactoryUtils.java @@ -15,19 +15,6 @@ public final class RulesetsFactoryUtils { private RulesetsFactoryUtils() {} - /** - * Creates a new rulesets with the given string. The resulting rulesets will contain - * all referenced rulesets. - * @param rulesets the string with the rulesets to load - * @param factory the ruleset factory - * @return the rulesets - * @throws IllegalArgumentException if rulesets is empty (means, no rules have been found) or if a - * ruleset couldn't be found. - */ - public static RuleSets getRuleSets(String rulesets, RuleSetFactory factory) { - return getRuleSets(rulesets, null, factory); - } - /** * Creates a new rulesets with the given string. The resulting rulesets will contain * all referenced rulesets. @@ -66,30 +53,15 @@ public final class RulesetsFactoryUtils { * @throws IllegalArgumentException if rulesets is empty (means, no rules have been found) or if a * ruleset couldn't be found. */ - public static RuleSets getRuleSetsWithBenchmark(String rulesets, RuleSetFactory factory) { - return getRuleSetsWithBenchmark(rulesets, null, factory); - } - - /** - * See {@link #getRuleSets(String, RuleSetFactory)}. In addition, the loading of the rules - * is benchmarked. - * @param rulesets the string with the rulesets to load - * @param pmdRuleSets RuleSets initialized in PMDConfiguration - * @param factory the ruleset factory - * @return the rulesets - * @throws IllegalArgumentException if rulesets is empty (means, no rules have been found) or if a - * ruleset couldn't be found. - */ public static RuleSets getRuleSetsWithBenchmark(String rulesets, RuleSets pmdRuleSets, RuleSetFactory factory) { long loadRuleStart = System.nanoTime(); - RuleSets ruleSets = null; try { - ruleSets = getRuleSets(rulesets, pmdRuleSets, factory); + pmdRuleSets = getRuleSets(rulesets, pmdRuleSets, factory); } finally { long endLoadRules = System.nanoTime(); Benchmarker.mark(Benchmark.LoadRules, endLoadRules - loadRuleStart, 0); } - return ruleSets; + return pmdRuleSets; } public static RuleSetFactory getRulesetFactory(PMDConfiguration configuration) { diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java index eb0fc98403..c6b3f641d7 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java @@ -57,7 +57,7 @@ public class RuleSetFactoryTest { Assert.assertNotNull("Test ruleset not found - can't continue with test!", in); RuleSetFactory rsf = new RuleSetFactory(); - RuleSets rs = rsf.createRuleSets("net/sourceforge/pmd/rulesets/reference-ruleset.xml"); + RuleSets rs = rsf.createRuleSets("net/sourceforge/pmd/rulesets/reference-ruleset.xml", null); // added by referencing a complete ruleset (TestRuleset1.xml) assertNotNull(rs.getRuleByName("MockRule1")); assertNotNull(rs.getRuleByName("MockRule2")); 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 023bbc6d2e..f6e12f06a5 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 @@ -50,7 +50,7 @@ public abstract class RuleTst { */ public Rule findRule(String ruleSet, String ruleName) { try { - Rule rule = new RuleSetFactory().createRuleSets(ruleSet).getRuleByName(ruleName); + Rule rule = new RuleSetFactory().createRuleSets(ruleSet, null).getRuleByName(ruleName); if (rule == null) { fail("Rule " + ruleName + " not found in ruleset " + ruleSet); } From 4a0802a2698a233bf88c4d965ebb135a65487821 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 10 Mar 2016 20:07:04 +0100 Subject: [PATCH 3/4] Revert "RuleSetFactory Performance Enhancement:-" This reverts commit 9da51952efb1671d664b20ffb3d49506e34d0818. --- .../main/java/net/sourceforge/pmd/PMD.java | 3 +-- .../net/sourceforge/pmd/PMDConfiguration.java | 19 ------------------- .../net/sourceforge/pmd/RuleSetFactory.java | 7 ++----- .../sourceforge/pmd/RulesetsFactoryUtils.java | 12 ++++++------ .../pmd/ant/internal/PMDTaskImpl.java | 2 +- .../pmd/processor/AbstractPMDProcessor.java | 2 +- .../pmd/processor/MonoThreadProcessor.java | 1 - .../pmd/processor/MultiThreadProcessor.java | 1 - .../pmd/processor/PmdRunnable.java | 7 +++---- .../sourceforge/pmd/RuleSetFactoryTest.java | 2 +- .../pmd/testframework/RuleTst.java | 2 +- 11 files changed, 16 insertions(+), 42 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PMD.java b/pmd-core/src/main/java/net/sourceforge/pmd/PMD.java index f545e551a8..0eda16cd36 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PMD.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PMD.java @@ -217,8 +217,7 @@ public class PMD { // Load the RuleSets RuleSetFactory ruleSetFactory = RulesetsFactoryUtils.getRulesetFactory(configuration); - RuleSets ruleSets = RulesetsFactoryUtils.getRuleSetsWithBenchmark(configuration.getRuleSets(), configuration.getPmdRuleSets(), ruleSetFactory); - configuration.setPmdRuleSets(ruleSets); + RuleSets ruleSets = RulesetsFactoryUtils.getRuleSetsWithBenchmark(configuration.getRuleSets(), ruleSetFactory); if (ruleSets == null) { return 0; } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java index 8c1113bb82..e85b5ea475 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java @@ -91,7 +91,6 @@ public class PMDConfiguration extends AbstractConfiguration { // Rule and source file options private String ruleSets; - private RuleSets pmdRuleSets; private RulePriority minimumPriority = RulePriority.LOW; private String inputPaths; private String inputUri; @@ -269,24 +268,6 @@ public class PMDConfiguration extends AbstractConfiguration { } /** - * Get the RuleSets. - * - * @return the pmdRuleSets - */ - public RuleSets getPmdRuleSets() { - return pmdRuleSets; - } - - /** - * Set the RuleSets - * - * @param pmdRuleSets the pmdRuleSets to set - */ - public void setPmdRuleSets(RuleSets pmdRuleSets) { - this.pmdRuleSets = pmdRuleSets; - } - - /** * Get the minimum priority threshold when loading Rules from RuleSets. * * @return The minimum priority threshold. diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java index e4f93d0693..88fe46ed13 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java @@ -105,20 +105,17 @@ public class RuleSetFactory { } /** - * Create a RuleSets from a comma separated list of RuleSet reference IDs when the parameter ruleSets is null. + * Create a RuleSets from a comma separated list of RuleSet reference IDs. * This is a convenience method which calls * {@link RuleSetReferenceId#parse(String)}, and then calls * {@link #createRuleSets(List)}. The currently configured ClassLoader is * used. * * @param referenceString A comma separated list of RuleSet reference IDs. - * @param ruleSets RuleSets initialized in PMDConfiguration. * @return The new RuleSets. * @throws RuleSetNotFoundException if unable to find a resource. */ - public synchronized RuleSets createRuleSets(String referenceString, RuleSets ruleSets) throws RuleSetNotFoundException { - if(ruleSets != null) - return ruleSets; + public synchronized RuleSets createRuleSets(String referenceString) throws RuleSetNotFoundException { return createRuleSets(RuleSetReferenceId.parse(referenceString)); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RulesetsFactoryUtils.java b/pmd-core/src/main/java/net/sourceforge/pmd/RulesetsFactoryUtils.java index 0e5d668454..1ba017e78d 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RulesetsFactoryUtils.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RulesetsFactoryUtils.java @@ -20,16 +20,15 @@ public final class RulesetsFactoryUtils { * all referenced rulesets. * @param rulesets the string with the rulesets to load * @param factory the ruleset factory - * @param pmdRuleSets RuleSets initialized in PMDConfiguration * @return the rulesets * @throws IllegalArgumentException if rulesets is empty (means, no rules have been found) or if a * ruleset couldn't be found. */ - public static RuleSets getRuleSets(String rulesets, RuleSets pmdRuleSets, RuleSetFactory factory) { + public static RuleSets getRuleSets(String rulesets, RuleSetFactory factory) { RuleSets ruleSets = null; try { factory.setWarnDeprecated(true); - ruleSets = factory.createRuleSets(rulesets, pmdRuleSets); + ruleSets = factory.createRuleSets(rulesets); factory.setWarnDeprecated(false); printRuleNamesInDebug(ruleSets); if (ruleSets.ruleCount() == 0) { @@ -53,15 +52,16 @@ public final class RulesetsFactoryUtils { * @throws IllegalArgumentException if rulesets is empty (means, no rules have been found) or if a * ruleset couldn't be found. */ - public static RuleSets getRuleSetsWithBenchmark(String rulesets, RuleSets pmdRuleSets, RuleSetFactory factory) { + public static RuleSets getRuleSetsWithBenchmark(String rulesets, RuleSetFactory factory) { long loadRuleStart = System.nanoTime(); + RuleSets ruleSets = null; try { - pmdRuleSets = getRuleSets(rulesets, pmdRuleSets, factory); + ruleSets = getRuleSets(rulesets, factory); } finally { long endLoadRules = System.nanoTime(); Benchmarker.mark(Benchmark.LoadRules, endLoadRules - loadRuleStart, 0); } - return pmdRuleSets; + return ruleSets; } public static RuleSetFactory getRulesetFactory(PMDConfiguration configuration) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java b/pmd-core/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java index 59b49219f3..83c13eca87 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/ant/internal/PMDTaskImpl.java @@ -110,7 +110,7 @@ public class PMDTaskImpl { // Substitute env variables/properties configuration.setRuleSets(project.replaceProperties(ruleSets)); } - RuleSets rules = ruleSetFactory.createRuleSets(configuration.getRuleSets(), configuration.getPmdRuleSets()); + RuleSets rules = ruleSetFactory.createRuleSets(configuration.getRuleSets()); ruleSetFactory.setWarnDeprecated(false); logRulesUsed(rules); } catch (RuleSetNotFoundException e) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/processor/AbstractPMDProcessor.java b/pmd-core/src/main/java/net/sourceforge/pmd/processor/AbstractPMDProcessor.java index 462094fe49..75818637ec 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/processor/AbstractPMDProcessor.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/processor/AbstractPMDProcessor.java @@ -51,7 +51,7 @@ public abstract class AbstractPMDProcessor { } protected RuleSets createRuleSets(RuleSetFactory factory) { - return RulesetsFactoryUtils.getRuleSets(configuration.getRuleSets(), configuration.getPmdRuleSets(), factory); + return RulesetsFactoryUtils.getRuleSets(configuration.getRuleSets(), factory); } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/processor/MonoThreadProcessor.java b/pmd-core/src/main/java/net/sourceforge/pmd/processor/MonoThreadProcessor.java index 253d370b17..c71fc8e620 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/processor/MonoThreadProcessor.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/processor/MonoThreadProcessor.java @@ -39,7 +39,6 @@ public final class MonoThreadProcessor extends AbstractPMDProcessor { // single threaded execution RuleSets rs = createRuleSets(ruleSetFactory); - configuration.setPmdRuleSets(rs); SourceCodeProcessor processor = new SourceCodeProcessor(configuration); for (DataSource dataSource : files) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/processor/MultiThreadProcessor.java b/pmd-core/src/main/java/net/sourceforge/pmd/processor/MultiThreadProcessor.java index f3c559197b..4825640fbb 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/processor/MultiThreadProcessor.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/processor/MultiThreadProcessor.java @@ -36,7 +36,6 @@ public class MultiThreadProcessor extends AbstractPMDProcessor { final RuleContext ctx, final List renderers) { RuleSets rs = createRuleSets(ruleSetFactory); - configuration.setPmdRuleSets(rs); rs.start(ctx); PmdThreadFactory factory = new PmdThreadFactory(ruleSetFactory, ctx); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/processor/PmdRunnable.java b/pmd-core/src/main/java/net/sourceforge/pmd/processor/PmdRunnable.java index fdf8bc1ee3..6e898d6495 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/processor/PmdRunnable.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/processor/PmdRunnable.java @@ -60,8 +60,7 @@ public class PmdRunnable extends PMD implements Callable { PmdThread thread = (PmdThread) Thread.currentThread(); RuleContext ctx = thread.getRuleContext(); - RuleSets rs = thread.getRuleSets(configuration.getRuleSets(), configuration.getPmdRuleSets()); - configuration.setPmdRuleSets(rs); + RuleSets rs = thread.getRuleSets(configuration.getRuleSets()); Report report = setupReport(rs, ctx, fileName); @@ -110,10 +109,10 @@ public class PmdRunnable extends PMD implements Callable { return context; } - public RuleSets getRuleSets(String rsList, RuleSets ruleSets) { + public RuleSets getRuleSets(String rsList) { if (rulesets == null) { try { - rulesets = ruleSetFactory.createRuleSets(rsList, ruleSets); + rulesets = ruleSetFactory.createRuleSets(rsList); } catch (Exception e) { e.printStackTrace(); } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java index c6b3f641d7..eb0fc98403 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java @@ -57,7 +57,7 @@ public class RuleSetFactoryTest { Assert.assertNotNull("Test ruleset not found - can't continue with test!", in); RuleSetFactory rsf = new RuleSetFactory(); - RuleSets rs = rsf.createRuleSets("net/sourceforge/pmd/rulesets/reference-ruleset.xml", null); + RuleSets rs = rsf.createRuleSets("net/sourceforge/pmd/rulesets/reference-ruleset.xml"); // added by referencing a complete ruleset (TestRuleset1.xml) assertNotNull(rs.getRuleByName("MockRule1")); assertNotNull(rs.getRuleByName("MockRule2")); 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 f6e12f06a5..023bbc6d2e 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 @@ -50,7 +50,7 @@ public abstract class RuleTst { */ public Rule findRule(String ruleSet, String ruleName) { try { - Rule rule = new RuleSetFactory().createRuleSets(ruleSet, null).getRuleByName(ruleName); + Rule rule = new RuleSetFactory().createRuleSets(ruleSet).getRuleByName(ruleName); if (rule == null) { fail("Rule " + ruleName + " not found in ruleset " + ruleSet); } From 5f9e90761d2c0ea5ecceac3da01213724c4f05c2 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 10 Mar 2016 20:12:13 +0100 Subject: [PATCH 4/4] Fixes #1461 Possible threading issue due to PR#75 Update changelog --- src/site/markdown/overview/changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index a54d5d4707..27495cfc63 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -45,6 +45,7 @@ * [#1456](https://sourceforge.net/p/pmd/bugs/1456/): UnusedFormalParameter should ignore overriding methods * General * [#1455](https://sourceforge.net/p/pmd/bugs/1455/): PMD doesn't handle Java 8 explicit receiver parameters + * [#1461](https://sourceforge.net/p/pmd/bugs/1461/): Possible threading issue due to PR#75 **API Changes:**