Skip to content

Commit

Permalink
Don't crash on an "empty" method with a redundant return.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 450727959
  • Loading branch information
amalloy authored and Error Prone Team committed May 24, 2022
1 parent 464b218 commit 81acea9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ public Boolean visitBlock(BlockTree tree, Void unused) {
@Override
public Boolean visitReturn(ReturnTree tree, Void unused) {
ExpressionTree expression = tree.getExpression();
if (constantExpressions.constantExpression(expression, state).isPresent()) {
if (expression == null
|| constantExpressions.constantExpression(expression, state).isPresent()) {
return true;
}
return scan(tree.getExpression(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ public void ignoreEmptyOverride() {
" super.f();",
" }",
" }",
" class D extends Lib {",
" public void f() {",
" return;",
" }",
" }",
"}")
.doTest();
}
Expand Down

0 comments on commit 81acea9

Please sign in to comment.