diff --git a/pmd/src/net/sourceforge/pmd/rules/regex/RegexHelper.java b/pmd/src/net/sourceforge/pmd/rules/regex/RegexHelper.java index 3547893774..d528401d4a 100644 --- a/pmd/src/net/sourceforge/pmd/rules/regex/RegexHelper.java +++ b/pmd/src/net/sourceforge/pmd/rules/regex/RegexHelper.java @@ -25,22 +25,36 @@ public class RegexHelper { * @return */ public static List compilePatternFromList(List list) { - List patterns = new ArrayList(list.size()); - for (String stringPattern : list) { - if ( stringPattern != null && stringPattern.length() > 0 ) { - patterns.add(Pattern.compile(stringPattern)); - } else { - throw new IllegalArgumentException("The following pattern is not valid:" + stringPattern); + List patterns; + if (list != null && list.size() > 0) { + patterns = new ArrayList(list.size()); + for (String stringPattern : list) { + if ( stringPattern != null && ! "".equals(stringPattern) ) { + patterns.add(Pattern.compile(stringPattern)); + } } } + else + patterns = new ArrayList(0); return patterns; } - public static boolean isMatch(Pattern pattern,String image) { - Matcher matcher = pattern.matcher(image); - if (matcher.find()) { - return true; - } + /** + *

Simple commidity method (also designed to increase readability of source code, + * and to decrease import in the calling class).

+ *

Provide a pattern and a subject, it'll do the proper matching.

+ * + * @param pattern, a compiled regex pattern. + * @param subject, a String to match + * @return + */ + public static boolean isMatch(Pattern pattern,String subject) { + if ( subject != null && "".equals(subject) ) { + Matcher matcher = pattern.matcher(subject); + if (matcher.find()) { + return true; + } + } return false; }