Skip to content

Commit

Permalink
Allow CONST_CASE != null in YodaCondition
Browse files Browse the repository at this point in the history
Follow-up to 9b2c2a9

PiperOrigin-RevId: 622020333
  • Loading branch information
cushon authored and Error Prone Team committed Apr 5, 2024
1 parent 200eb43 commit 23547ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Expand Up @@ -120,6 +120,9 @@ private static boolean seemsConstant(Tree tree) {
if (constValue(tree) != null) {
return true;
}
if (tree.getKind().equals(Tree.Kind.NULL_LITERAL)) {
return true;
}
var symbol = getSymbol(tree);
if (!(symbol instanceof VarSymbol)) {
return false;
Expand Down
Expand Up @@ -18,6 +18,7 @@

import com.google.errorprone.BugCheckerRefactoringTestHelper;
import com.google.errorprone.BugCheckerRefactoringTestHelper.FixChoosers;
import com.google.errorprone.CompilationTestHelper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -27,6 +28,9 @@ public final class YodaConditionTest {
private final BugCheckerRefactoringTestHelper refactoring =
BugCheckerRefactoringTestHelper.newInstance(YodaCondition.class, getClass());

private final CompilationTestHelper testHelper =
CompilationTestHelper.newInstance(YodaCondition.class, getClass());

@Test
public void primitive() {
refactoring
Expand Down Expand Up @@ -205,4 +209,18 @@ public void provablyNonNull_nullIntolerantFix() {
"}")
.doTest();
}

@Test
public void nullableConstant() {
testHelper
.addSourceLines(
"Test.java",
"class Test {",
" private static final String CONST = null;",
" public static boolean f() {",
" return CONST != null;",
" }",
"}")
.doTest();
}
}

0 comments on commit 23547ac

Please sign in to comment.