Skip to content

Commit 81acea9

Browse files
amalloyError Prone Team
authored and
Error Prone Team
committed
Don't crash on an "empty" method with a redundant return.
PiperOrigin-RevId: 450727959
1 parent 464b218 commit 81acea9

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

core/src/main/java/com/google/errorprone/bugpatterns/UnsynchronizedOverridesSynchronized.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ public Boolean visitBlock(BlockTree tree, Void unused) {
121121
@Override
122122
public Boolean visitReturn(ReturnTree tree, Void unused) {
123123
ExpressionTree expression = tree.getExpression();
124-
if (constantExpressions.constantExpression(expression, state).isPresent()) {
124+
if (expression == null
125+
|| constantExpressions.constantExpression(expression, state).isPresent()) {
125126
return true;
126127
}
127128
return scan(tree.getExpression(), null);

core/src/test/java/com/google/errorprone/bugpatterns/UnsynchronizedOverridesSynchronizedTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ public void ignoreEmptyOverride() {
157157
" super.f();",
158158
" }",
159159
" }",
160+
" class D extends Lib {",
161+
" public void f() {",
162+
" return;",
163+
" }",
164+
" }",
160165
"}")
161166
.doTest();
162167
}

0 commit comments

Comments
 (0)