diff --git a/pom.xml b/pom.xml
index b27976e4b..663d14e66 100644
--- a/pom.xml
+++ b/pom.xml
@@ -584,7 +584,7 @@
.*.PropertiesExpander5083
.*.PropertyCacheFile2218
.*.TreeWalker9083
- com.puppycrawl.tools.checkstyle.Utils6963
+ com.puppycrawl.tools.checkstyle.Utils6969
.*.XMLLogger8697
@@ -830,11 +830,11 @@
.*.filters.IntMatchFilter10090
.*.filters.IntRangeFilter10090
.*.filters.SuppressElement6978
- .*.filters.SuppressionCommentFilter8586
+ .*.filters.SuppressionCommentFilter8387
.*.filters.SuppressionCommentFilter\$.*8784
.*.filters.SuppressionFilter00
.*.filters.SuppressionsLoader6877
- .*.filters.SuppressWithNearbyCommentFilter8087
+ .*.filters.SuppressWithNearbyCommentFilter7689
.*.filters.SuppressWithNearbyCommentFilter\$.*8175
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/Utils.java b/src/main/java/com/puppycrawl/tools/checkstyle/Utils.java
index 3904847c3..cf56f1868 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/Utils.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/Utils.java
@@ -168,9 +168,25 @@ public final class Utils
}
/**
- * This is a factory method to return an Pattern object for the specified
- * regular expression. It calls {@link #getPattern(String, int)} with the
- * compile flags defaults to 0.
+ * Validates whether passed string is a valid pattern or not.
+ * @param pattern
+ * string to validate
+ * @return true if the pattern is valid false otherwise
+ */
+ public static boolean isPatternValid(String pattern)
+ {
+ try {
+ Utils.getPattern(pattern);
+ }
+ catch (final PatternSyntaxException e) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * This is a factory method to return an Pattern object for the specified regular expression. It
+ * calls {@link #getPattern(String, int)} with the compile flags defaults to 0.
* @return an Pattern object for the supplied pattern
* @param pattern the regular expression pattern
* @throws PatternSyntaxException an invalid pattern was supplied
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressWithNearbyCommentFilter.java b/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressWithNearbyCommentFilter.java
index 33f865501..da65edb60 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressWithNearbyCommentFilter.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressWithNearbyCommentFilter.java
@@ -376,12 +376,8 @@ public class SuppressWithNearbyCommentFilter
public void setMessageFormat(String format)
throws ConversionException
{
- // check that format parses
- try {
- Utils.getPattern(format);
- }
- catch (final PatternSyntaxException e) {
- throw new ConversionException("unable to parse " + format, e);
+ if (!Utils.isPatternValid(format)) {
+ throw new ConversionException("Unable to parse format: " + format);
}
messageFormat = format;
}
@@ -394,12 +390,8 @@ public class SuppressWithNearbyCommentFilter
public void setInfluenceFormat(String format)
throws ConversionException
{
- // check that format parses
- try {
- Utils.getPattern(format);
- }
- catch (final PatternSyntaxException e) {
- throw new ConversionException("unable to parse " + format, e);
+ if (!Utils.isPatternValid(format)) {
+ throw new ConversionException("Unable to parse format: " + format);
}
influenceFormat = format;
}
diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionCommentFilter.java b/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionCommentFilter.java
index 2b9a505ce..6a7ffc316 100644
--- a/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionCommentFilter.java
+++ b/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionCommentFilter.java
@@ -374,12 +374,8 @@ public class SuppressionCommentFilter
public void setMessageFormat(String format)
throws ConversionException
{
- // check that format parses
- try {
- Utils.getPattern(format);
- }
- catch (final PatternSyntaxException e) {
- throw new ConversionException("unable to parse " + format, e);
+ if (!Utils.isPatternValid(format)) {
+ throw new ConversionException("Unable to parse format: " + format);
}
messageFormat = format;
}