Skip to content

Commit

Permalink
Fix a bug in AlreadyChecked involving if statements where the clauses…
Browse files Browse the repository at this point in the history
… aren't block statements

Fixes #3914

PiperOrigin-RevId: 532573468
  • Loading branch information
cushon authored and Error Prone Team committed May 16, 2023
1 parent c084186 commit 31d420b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public Void visitThrow(ThrowTree tree, Void unused) {

private void handleMethodExitingStatement() {
TreePath ifPath = getCurrentPath().getParentPath();
Tree previous = null;
Tree previous = getCurrentPath().getLeaf();
while (ifPath != null && ifPath.getLeaf() instanceof BlockTree) {
previous = ifPath.getLeaf();
ifPath = ifPath.getParentPath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,4 +498,22 @@ public void equalsCalledTwiceOnMutableType_noFinding() {
"}")
.doTest();
}

@Test
public void i3914() {
helper
.addSourceLines(
"Test.java",
"import java.util.List;",
"class Test {",
" void test(boolean a, boolean b) {",
" if (a && b)",
" return;",
" if (a) {",
" } else if (b) {",
" }",
" }",
"}")
.doTest();
}
}

0 comments on commit 31d420b

Please sign in to comment.