diff --git a/pom.xml b/pom.xml index dabaa4a29..06e143220 100644 --- a/pom.xml +++ b/pom.xml @@ -232,6 +232,12 @@ 1.9.0 test + + nl.jqno.equalsverifier + equalsverifier + 1.7.2 + test + @@ -893,7 +899,7 @@ .*.filters.SuppressionFilter00 .*.filters.SuppressionsLoader6877 .*.filters.SuppressWithNearbyCommentFilter7689 - .*.filters.SuppressWithNearbyCommentFilter\$.*4763 + .*.filters.SuppressWithNearbyCommentFilter\$Tag8878 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 490c9590a..3d0b04a84 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressWithNearbyCommentFilter.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressWithNearbyCommentFilter.java @@ -85,16 +85,16 @@ public class SuppressWithNearbyCommentFilter private final String text; /** The first line where warnings may be suppressed. */ - private int firstLine; + private final int firstLine; /** The last line where warnings may be suppressed. */ - private int lastLine; + private final int lastLine; /** The parsed check regexp, expanded for the text of this tag. */ - private Pattern tagCheckRegexp; + private final Pattern tagCheckRegexp; /** The parsed message regexp, expanded for the text of this tag. */ - private Pattern tagMessageRegexp; + private final Pattern tagMessageRegexp; /** * Constructs a tag. @@ -108,7 +108,6 @@ public class SuppressWithNearbyCommentFilter throws ConversionException { this.text = text; - tagCheckRegexp = filter.checkRegexp; //Expand regexp for check and message //Does not intern Patterns with Utils.getPattern() String format = ""; @@ -120,6 +119,9 @@ public class SuppressWithNearbyCommentFilter text, filter.messageFormat, filter.commentRegexp); tagMessageRegexp = Pattern.compile(format); } + else { + tagMessageRegexp = null; + } int influence = 0; if (filter.influenceFormat != null) { format = expandFrocomment( @@ -289,9 +291,6 @@ public class SuppressWithNearbyCommentFilter /** The comment pattern that triggers suppression. */ private String checkFormat; - /** The parsed check regexp. */ - private Pattern checkRegexp; - /** The message format to suppress. */ private String messageFormat; @@ -355,9 +354,7 @@ public class SuppressWithNearbyCommentFilter * @param format a String value * @throws ConversionException if unable to create Pattern object */ - public void setCheckFormat(String format) - throws ConversionException { - checkRegexp = Utils.createPattern(format); + public void setCheckFormat(String format) throws ConversionException { checkFormat = format; } diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressWithNearbyCommentFilterTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressWithNearbyCommentFilterTest.java index 5086390db..e0d7daf8b 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressWithNearbyCommentFilterTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/filters/SuppressWithNearbyCommentFilterTest.java @@ -35,6 +35,8 @@ import java.io.UnsupportedEncodingException; import java.util.Arrays; import java.util.Collection; import java.util.Locale; + +import nl.jqno.equalsverifier.EqualsVerifier; import org.junit.Test; public class SuppressWithNearbyCommentFilterTest @@ -172,6 +174,10 @@ public class SuppressWithNearbyCommentFilterTest verifySuppressed(filterConfig, suppressed); } + @Test + public void testEqualsAndHashCodeOfTagClass() { + EqualsVerifier.forClass(SuppressWithNearbyCommentFilter.Tag.class).usingGetClass().verify(); + } public static DefaultConfiguration createFilterConfig(Class classObj) { return new DefaultConfiguration(classObj.getName());