From 754efd84a67f78dfd04223e8e37450591e7d2908 Mon Sep 17 00:00:00 2001 From: Kurt Alfred Kluever Date: Wed, 1 Jul 2026 08:37:06 -0700 Subject: [PATCH] In the `Contains` matcher, return `null` when the input `tree` is `null`. h/t to cpovirk@ who spelunked this :-) PiperOrigin-RevId: 941115105 --- .../java/com/google/errorprone/matchers/Contains.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/check_api/src/main/java/com/google/errorprone/matchers/Contains.java b/check_api/src/main/java/com/google/errorprone/matchers/Contains.java index 5882e60e344..ad83c1641e0 100644 --- a/check_api/src/main/java/com/google/errorprone/matchers/Contains.java +++ b/check_api/src/main/java/com/google/errorprone/matchers/Contains.java @@ -19,6 +19,7 @@ import com.google.errorprone.VisitorState; import com.sun.source.tree.Tree; import com.sun.source.util.TreeScanner; +import org.jspecify.annotations.Nullable; /** * 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) { private boolean matchFound = false; @Override - public Void scan(Tree tree, Void unused) { - if (matchFound || matcher.matches(tree, state)) { + public Void scan(@Nullable Tree tree, Void unused) { + if (tree == null || matchFound) { + return null; + } + if (matcher.matches(tree, state)) { matchFound = true; return null; }