From 957afd6625197fba8e020e7b51395deb712e5648 Mon Sep 17 00:00:00 2001 From: Henning Schmiedehausen Date: Tue, 26 Nov 2013 11:00:49 -0800 Subject: [PATCH] Fix NPE with empty rulesets. This is the fix for bug #1155 (https://sourceforge.net/p/pmd/bugs/1155/) The whole code is in dire need of revisiting its behaviour when a value is null or empty. Same goes for e.g. createRules whether it should return null values (then the caller will have to deal with it) or empty Rulesets. Catching and discarding the rule not found exception looks pretty suspicious. --- .../java/net/sourceforge/pmd/RuleSetReferenceId.java | 12 +++++++----- .../pmd/processor/AbstractPMDProcessor.java | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pmd/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java b/pmd/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java index 841df1b6e4..f9df6c6927 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java +++ b/pmd/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java @@ -251,11 +251,13 @@ public class RuleSetReferenceId { */ public static List parse(String referenceString) { List references = new ArrayList(); - if (referenceString.indexOf(',') == -1) { - references.add(new RuleSetReferenceId(referenceString)); - } else { - for (String name : referenceString.split(",")) { - references.add(new RuleSetReferenceId(name)); + if (referenceString != null && referenceString.trim().length() > 0) { + if (referenceString.indexOf(',') == -1) { + references.add(new RuleSetReferenceId(referenceString)); + } else { + for (String name : referenceString.split(",")) { + references.add(new RuleSetReferenceId(name)); + } } } return references; diff --git a/pmd/src/main/java/net/sourceforge/pmd/processor/AbstractPMDProcessor.java b/pmd/src/main/java/net/sourceforge/pmd/processor/AbstractPMDProcessor.java index fa063bcd48..d17b273ea7 100644 --- a/pmd/src/main/java/net/sourceforge/pmd/processor/AbstractPMDProcessor.java +++ b/pmd/src/main/java/net/sourceforge/pmd/processor/AbstractPMDProcessor.java @@ -56,7 +56,7 @@ public abstract class AbstractPMDProcessor { return factory.createRuleSets(configuration.getRuleSets()); } catch (RuleSetNotFoundException rsnfe) { // should not happen: parent already created a ruleset - return null; + return new RuleSets(); } }