Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow CONST_CASE != null in YodaCondition #4361

Merged
merged 1 commit into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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();
}
}
Loading