diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/Main.java b/src/main/java/com/puppycrawl/tools/checkstyle/Main.java index c203f08f6..74ac3e57b 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/Main.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/Main.java @@ -67,7 +67,6 @@ public final class Main { boolean cliViolations = false; // provide proper exit code based on results. final int exitWithCliViolation = -1; - final int exitWithCheckstyleException = -2; int exitStatus = 0; try { @@ -109,6 +108,7 @@ public final class Main { printUsage(); } catch (CheckstyleException e) { + final int exitWithCheckstyleException = -2; exitStatus = exitWithCheckstyleException; errorCounter = 1; System.out.println(e.getMessage()); diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/PropertyCacheFile.java b/src/main/java/com/puppycrawl/tools/checkstyle/PropertyCacheFile.java index dc5ae7cc8..fa6e7c82c 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/PropertyCacheFile.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/PropertyCacheFile.java @@ -100,11 +100,11 @@ final class PropertyCacheFile { * @throws IOException when there is a problems with file read */ void load() throws IOException { - FileInputStream inStream = null; // get the current config so if the file isn't found // the first time the hash will be added to output file final String currentConfigHash = getConfigHashCode(config); if (new File(fileName).exists()) { + FileInputStream inStream = null; try { inStream = new FileInputStream(fileName); details.load(inStream); diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/api/FileText.java b/src/main/java/com/puppycrawl/tools/checkstyle/api/FileText.java index 53ac44685..ec0b00351 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/api/FileText.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/FileText.java @@ -122,17 +122,16 @@ public final class FileText extends AbstractList { } catch (final UnsupportedCharsetException ex) { final String message = "Unsupported charset: " + charsetName; - final UnsupportedEncodingException ex2; - ex2 = new UnsupportedEncodingException(message); + final UnsupportedEncodingException ex2 = new UnsupportedEncodingException(message); ex2.initCause(ex); throw ex2; } - final char[] chars = new char[READ_BUFFER_SIZE]; final StringBuilder buf = new StringBuilder(); final FileInputStream stream = new FileInputStream(file); final Reader reader = new InputStreamReader(stream, decoder); try { + final char[] chars = new char[READ_BUFFER_SIZE]; while (true) { final int len = reader.read(chars); if (len < 0) { diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/api/LocalizedMessage.java b/src/main/java/com/puppycrawl/tools/checkstyle/api/LocalizedMessage.java index c389553bb..889a6642a 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/api/LocalizedMessage.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/api/LocalizedMessage.java @@ -371,7 +371,6 @@ public final class LocalizedMessage // The below is a copy of the default implementation. final String bundleName = toBundleName(aBaseName, aLocale); final String resourceName = toResourceName(bundleName, "properties"); - ResourceBundle bundle = null; InputStream stream = null; if (aReload) { final URL url = aLoader.getResource(resourceName); @@ -386,6 +385,7 @@ public final class LocalizedMessage else { stream = aLoader.getResourceAsStream(resourceName); } + ResourceBundle bundle = null; if (stream != null) { final Reader streamReader = new InputStreamReader(stream, "UTF-8"); try { diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/AvoidEscapedUnicodeCharactersCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/AvoidEscapedUnicodeCharactersCheck.java index 1379d3380..6aa72449f 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/AvoidEscapedUnicodeCharactersCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/AvoidEscapedUnicodeCharactersCheck.java @@ -244,7 +244,6 @@ public class AvoidEscapedUnicodeCharactersCheck * @return true if trail comment is present after ast token. */ private boolean hasTrailComment(DetailAST ast) { - boolean result = false; final DetailAST variableDef = getVariableDef(ast); DetailAST semi; @@ -260,6 +259,7 @@ public class AvoidEscapedUnicodeCharactersCheck semi = getSemi(ast); } + boolean result = false; if (semi != null) { final int lineNo = semi.getLineNo(); final String currentLine = getLine(lineNo - 1); diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/NewlineAtEndOfFileCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/NewlineAtEndOfFileCheck.java index c52d2e877..70bda2bc6 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/NewlineAtEndOfFileCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/NewlineAtEndOfFileCheck.java @@ -79,9 +79,8 @@ public class NewlineAtEndOfFileCheck @Override protected void processFiltered(File file, List lines) { // Cannot use lines as the line separators have been removed! - RandomAccessFile randomAccessFile = null; try { - randomAccessFile = new RandomAccessFile(file, "r"); + final RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r"); boolean threw = true; try { if (!endsWithNewline(randomAccessFile)) { diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/CovariantEqualsCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/CovariantEqualsCheck.java index bd86a9716..46c4cea04 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/CovariantEqualsCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/CovariantEqualsCheck.java @@ -71,12 +71,12 @@ public class CovariantEqualsCheck extends Check { @Override public void visitToken(DetailAST ast) { equalsMethods.clear(); - boolean hasEqualsObject = false; // examine method definitions for equals methods final DetailAST objBlock = ast.findFirstToken(TokenTypes.OBJBLOCK); if (objBlock != null) { DetailAST child = objBlock.getFirstChild(); + boolean hasEqualsObject = false; while (child != null) { if (child.getType() == TokenTypes.METHOD_DEF && CheckUtils.isEqualsMethod(child)) { diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/RedundantImportCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/RedundantImportCheck.java index b59ba2058..7257f5007 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/RedundantImportCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/RedundantImportCheck.java @@ -154,13 +154,11 @@ public class RedundantImportCheck * @return whether from the package */ private static boolean fromPackage(String importName, String pkg) { - boolean retVal = false; // imports from unnamed package are not allowed: // http://docs.oracle.com/javase/specs/jls/se7/html/jls-7.html#jls-7.5 // So '.' must be present in member name and we are not checking for it final int index = importName.lastIndexOf('.'); final String front = importName.substring(0, index); - retVal = front.equals(pkg); - return retVal; + return front.equals(pkg); } } diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/HandlerFactory.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/HandlerFactory.java index 9a46da6aa..1b1bd094e 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/HandlerFactory.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/indentation/HandlerFactory.java @@ -143,12 +143,10 @@ public class HandlerFactory { return createMethodCallHandler(indentCheck, ast, parent); } - AbstractExpressionHandler expHandler = null; final Constructor handlerCtor = typeHandlers.get(ast.getType()); - expHandler = (AbstractExpressionHandler) Utils.invokeConstructor( - handlerCtor, indentCheck, ast, parent); - return expHandler; + return (AbstractExpressionHandler) Utils.invokeConstructor( + handlerCtor, indentCheck, ast, parent); } /** diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocStyleCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocStyleCheck.java index 39f9d2b58..0bd4b5dd3 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocStyleCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/javadoc/JavadocStyleCheck.java @@ -351,8 +351,7 @@ public class JavadocStyleCheck final Deque htmlStack = new ArrayDeque<>(); final String[] text = comment.getText(); - TagParser parser = null; - parser = new TagParser(text, lineno); + final TagParser parser = new TagParser(text, lineno); while (parser.hasNextTag()) { final HtmlTag tag = parser.nextTag(); diff --git a/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpCheck.java b/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpCheck.java index a88fc418b..9ed47bc56 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpCheck.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/checks/regexp/RegexpCheck.java @@ -186,17 +186,14 @@ public class RegexpCheck extends AbstractFormatCheck { /** recursive method that finds the matches. */ private void findMatch() { - int startLine; - boolean foundMatch; - boolean ignore = false; - foundMatch = matcher.find(); + final boolean foundMatch = matcher.find(); if (foundMatch) { final FileText text = getFileContents().getText(); final LineColumn start = text.lineColumn(matcher.start()); - startLine = start.getLine(); + final int startLine = start.getLine(); - ignore = isIgnore(startLine, text, start); + final boolean ignore = isIgnore(startLine, text, start); if (!ignore) { matchCount++; @@ -234,10 +231,6 @@ public class RegexpCheck extends AbstractFormatCheck { * @return true is that need to be ignored */ private boolean isIgnore(int startLine, FileText text, LineColumn start) { - int startColumn; - boolean ignore = false; - int endLine; - int endColumn; final LineColumn end; if (matcher.end() == 0) { end = text.lineColumn(0); @@ -245,9 +238,10 @@ public class RegexpCheck extends AbstractFormatCheck { else { end = text.lineColumn(matcher.end() - 1); } - startColumn = start.getColumn(); - endLine = end.getLine(); - endColumn = end.getColumn(); + final int startColumn = start.getColumn(); + final int endLine = end.getLine(); + final int endColumn = end.getColumn(); + boolean ignore = false; if (ignoreComments) { final FileContents theFileContents = getFileContents(); ignore = theFileContents.hasIntersectionWithComment(startLine, 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 19ce3e81f..6411ced4a 100644 --- a/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressWithNearbyCommentFilter.java +++ b/src/main/java/com/puppycrawl/tools/checkstyle/filters/SuppressWithNearbyCommentFilter.java @@ -122,9 +122,9 @@ public class SuppressWithNearbyCommentFilter else { tagMessageRegexp = null; } - int influence = 0; format = expandFrocomment( text, filter.influenceFormat, filter.commentRegexp); + int influence = 0; try { if (Utils.startsWithChar(format, '+')) { format = format.substring(1);