diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CanonicalConstantFieldName.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CanonicalConstantFieldName.java index 80a5614fec..17c181d33e 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CanonicalConstantFieldName.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/CanonicalConstantFieldName.java @@ -128,20 +128,16 @@ public Description matchCompilationUnit(CompilationUnitTree tree, VisitorState s if (IS_CONSTANT.matches(variableTree, state) && isFieldAccessModifierApplicable(variableTree, state)) { VarSymbol variableSymbol = ASTHelpers.getSymbol(variableTree); + String variableName = variableSymbol.getSimpleName().toString(); - if (variableSymbol != null) { - String variableName = variableSymbol.getSimpleName().toString(); + if (!isVariableUpperSnakeCase(variableName) && !isVariableNameExcluded(variableName)) { + String replacement = toUpperSnakeCase(variableName); - if (!isVariableUpperSnakeCase(variableName) - && !isVariableNameExcluded(variableName)) { - String replacement = toUpperSnakeCase(variableName); - - if (variableSymbols.stream() - .noneMatch(s -> s.getSimpleName().toString().equals(replacement))) { - fixBuilder.merge(SuggestedFixes.renameVariable(variableTree, replacement, state)); - } else { - reportConstantRenameBlocker(variableTree, replacement, state); - } + if (variableSymbols.stream() + .noneMatch(s -> s.getSimpleName().toString().equals(replacement))) { + fixBuilder.merge(SuggestedFixes.renameVariable(variableTree, replacement, state)); + } else { + reportConstantRenameBlocker(variableTree, replacement, state); } } } diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CanonicalConstantFieldNameTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CanonicalConstantFieldNameTest.java index 09415f681c..4379b3de37 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CanonicalConstantFieldNameTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/bugpatterns/CanonicalConstantFieldNameTest.java @@ -125,7 +125,7 @@ void excludeFlaggedConstants() { } @Test - void IncludePublicConstants() { + void includePublicConstants() { BugCheckerRefactoringTestHelper.newInstance(CanonicalConstantFieldName.class, getClass()) .setArgs("-XepOpt:CanonicalConstantFieldName:IncludePublicConstantFields=true") .addInputLines(