Skip to content

Commit

Permalink
Fix NPE in ReachabilityFenceUsage
Browse files Browse the repository at this point in the history
Fixes #2641

PiperOrigin-RevId: 415451162
  • Loading branch information
sumitbhagwani authored and Error Prone Team committed Dec 10, 2021
1 parent 88effaa commit 4b7ccd7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.sun.source.tree.MethodInvocationTree;
import com.sun.source.tree.Tree;
import com.sun.source.tree.TryTree;
import java.util.Objects;

/** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */
@BugPattern(
Expand All @@ -50,7 +51,7 @@ public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState
for (Tree enclosing : state.getPath().getParentPath()) {
switch (enclosing.getKind()) {
case TRY:
if (((TryTree) enclosing).getFinallyBlock().equals(previous)) {
if (Objects.equals(((TryTree) enclosing).getFinallyBlock(), previous)) {
return NO_MATCH;
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,24 @@ public void positive() {
.doTest();
}

@Test
public void positive_try() {
assumeTrue(RuntimeVersion.isAtLeast9());
compilationTestHelper
.addSourceLines(
"Test.java",
"import java.lang.ref.Reference;",
"class Test {",
" public void run() {",
" try {",
" // BUG: Diagnostic contains:",
" Reference.reachabilityFence(this);",
" } catch (Exception e) {}",
" }",
"}")
.doTest();
}

@Test
public void negative() {
assumeTrue(RuntimeVersion.isAtLeast9());
Expand Down

0 comments on commit 4b7ccd7

Please sign in to comment.