diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/Finalize.java b/core/src/main/java/com/google/errorprone/bugpatterns/Finalize.java index 6efa8864f56..828cabf7be5 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/Finalize.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/Finalize.java @@ -27,7 +27,7 @@ import com.google.errorprone.bugpatterns.BugChecker.MethodTreeMatcher; import com.google.errorprone.matchers.Description; import com.sun.source.tree.MethodTree; -import com.sun.tools.javac.code.Symbol.MethodSymbol; +import java.util.Set; import javax.lang.model.element.Modifier; /** A {@link BugChecker}; see the associated {@link BugPattern} annotation for details. */ @@ -45,8 +45,8 @@ public Description matchMethod(MethodTree tree, VisitorState state) { if (!isVoidType(getType(tree.getReturnType()), state)) { return NO_MATCH; } - MethodSymbol sym = getSymbol(tree); - if (!sym.getModifiers().contains(Modifier.PUBLIC)) { + Set modifiers = getSymbol(tree).getModifiers(); + if (!modifiers.contains(Modifier.PROTECTED) && !modifiers.contains(Modifier.PUBLIC)) { return NO_MATCH; } return describeMatch(tree); diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/FinalizeTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/FinalizeTest.java index 581b13da034..603cc59bf30 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/FinalizeTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/FinalizeTest.java @@ -34,7 +34,7 @@ public void positive() { "Test.java", "class Test {", " // BUG: Diagnostic contains: Do not override finalize", - " public void finalize() {}", + " protected void finalize() {}", " interface A {", " // BUG: Diagnostic contains: Do not override finalize", " void finalize();",