Skip to content

Commit 2d69875

Browse files
klueverError Prone Team
authored andcommitted
In the Contains matcher, return null when the input tree is null.
h/t to cpovirk@ who spelunked this :-) PiperOrigin-RevId: 941088114
1 parent 7691b5e commit 2d69875

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

  • check_api/src/main/java/com/google/errorprone/matchers

check_api/src/main/java/com/google/errorprone/matchers/Contains.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.errorprone.VisitorState;
2020
import com.sun.source.tree.Tree;
2121
import com.sun.source.util.TreeScanner;
22+
import org.jspecify.annotations.Nullable;
2223

2324
/**
2425
* A matcher that recursively inspects a tree, applying the given matcher to all levels of each tree
@@ -42,8 +43,11 @@ public boolean matches(Tree tree, VisitorState state) {
4243
private boolean matchFound = false;
4344

4445
@Override
45-
public Void scan(Tree tree, Void unused) {
46-
if (matchFound || matcher.matches(tree, state)) {
46+
public Void scan(@Nullable Tree tree, Void unused) {
47+
if (tree == null || matchFound) {
48+
return null;
49+
}
50+
if (matcher.matches(tree, state)) {
4751
matchFound = true;
4852
return null;
4953
}

0 commit comments

Comments
 (0)