From 1525df5b9259ebfe80365d8c448c09ff705d90fc Mon Sep 17 00:00:00 2001 From: cpovirk Date: Tue, 7 Nov 2023 11:04:51 -0800 Subject: [PATCH] Use `SuppressibleTreePathScanner` instead of rolling our own. This is already covered by tests, such as `negativeCases_suppressionForMethodTreeBased()`. (`SuppressibleTreePathScanner` might actually correct some edge cases somewhere, even.) PiperOrigin-RevId: 580238024 --- .../bugpatterns/nullness/ReturnMissingNullable.java | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/nullness/ReturnMissingNullable.java b/core/src/main/java/com/google/errorprone/bugpatterns/nullness/ReturnMissingNullable.java index e06bc53213b4..2f32a9dc2f07 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/nullness/ReturnMissingNullable.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/nullness/ReturnMissingNullable.java @@ -62,7 +62,6 @@ import com.sun.source.tree.MethodTree; import com.sun.source.tree.ReturnTree; import com.sun.source.tree.StatementTree; -import com.sun.source.tree.Tree; import com.sun.source.tree.VariableTree; import com.sun.source.util.TreePathScanner; import com.sun.tools.javac.code.Symbol; @@ -230,7 +229,7 @@ void doVisitVariable(VariableTree tree) { }.scan(tree, null); ImmutableSet definitelyNullVars = definitelyNullVarsBuilder.build(); - new TreePathScanner() { + new SuppressibleTreePathScanner(stateForCompilationUnit) { @Override public Void visitBlock(BlockTree block, Void unused) { for (StatementTree statement : block.getStatements()) { @@ -398,14 +397,6 @@ && methodCanBeOverridden(method)) { } } } - - @Override - public Void scan(Tree tree, Void unused) { - if (isSuppressed(tree, stateForCompilationUnit)) { - return null; - } - return super.scan(tree, unused); - } }.scan(tree, null); return NO_MATCH; // Any reports were made through state.reportMatch.