From 257983bcbfcd026266cb2cb6c556d701f2b9ba93 Mon Sep 17 00:00:00 2001 From: Michal Kordas Date: Fri, 14 Aug 2015 22:30:11 +0200 Subject: [PATCH] Mark fields as final. #1555 Fixes `FieldMayBeFinal` inspection violations. Description: >Reports any fields which may safely be made final. A static field may be final if it is initialized in its declaration or in one static class initializer, but not both. A non-static field may be final if it is initialized in its declaration or in one non-static class initializer or in all constructors. --- .../tools/checkstyle/checks/regexp/CommentSuppressor.java | 2 +- .../checkstyle/filters/SuppressionCommentFilter.java | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/CommentSuppressor.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/CommentSuppressor.java index 6dc76b09b..bf8613c86 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/CommentSuppressor.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/CommentSuppressor.java @@ -28,7 +28,7 @@ import com.puppycrawl.tools.checkstyle.api.FileContents; */ class CommentSuppressor implements MatchSuppressor { /** File contents to check for comments. */ - private FileContents currentContents; + private final FileContents currentContents; /** * Constructor for this suppressor. 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 dfbdbafa5..53c145a83 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionCommentFilter.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressionCommentFilter.java @@ -312,7 +312,7 @@ public class SuppressionCommentFilter 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. @@ -343,6 +343,9 @@ public class SuppressionCommentFilter expandFromCoont(text, filter.messageFormat, filter.onRegexp); tagMessageRegexp = Pattern.compile(format); } + else { + tagMessageRegexp = null; + } } else { format = @@ -356,6 +359,9 @@ public class SuppressionCommentFilter filter.offRegexp); tagMessageRegexp = Pattern.compile(format); } + else { + tagMessageRegexp = null; + } } } catch (final PatternSyntaxException e) {