Skip to content

Commit

Permalink
Suppress UnnecessarilyVisible findings on Error Prone bugchecker cons…
Browse files Browse the repository at this point in the history
…tructors

See #3706 (comment)

PiperOrigin-RevId: 501041647
  • Loading branch information
cushon authored and Error Prone Team committed Jan 10, 2023
1 parent ef13837 commit 4a71fa8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static com.google.errorprone.util.ASTHelpers.findSuperMethod;
import static com.google.errorprone.util.ASTHelpers.getSymbol;
import static com.google.errorprone.util.ASTHelpers.hasDirectAnnotationWithSimpleName;
import static com.google.errorprone.util.ASTHelpers.isSubtype;

import com.google.common.collect.ImmutableSet;
import com.google.errorprone.BugPattern;
Expand Down Expand Up @@ -93,6 +94,14 @@ public Description matchMethod(MethodTree tree, VisitorState state) {
if (badModifiers.isEmpty()) {
return NO_MATCH;
}
// TODO(b/263227221): Remove this once migration to guice is complete
if (symbol.isConstructor()
&& isSubtype(
symbol.enclClass().asType(),
state.getTypeFromString("com.google.errorprone.bugpatterns.BugChecker"),
state)) {
return NO_MATCH;
}
return buildDescription(tree)
.addFix(
removeModifiers(tree.getModifiers(), state, badModifiers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,4 +175,18 @@ public void overridesPublicMethod_noFinding() {
.expectUnchanged()
.doTest();
}

@Test
public void negativeBugchecker() {
compilationHelper
.addSourceLines(
"Test.java",
"import com.google.errorprone.bugpatterns.BugChecker;",
"import javax.inject.Inject;",
"class MyBugChecker extends BugChecker {",
" @Inject",
" public MyBugChecker() {}",
"}")
.doTest();
}
}

0 comments on commit 4a71fa8

Please sign in to comment.