diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/NonApiType.java b/core/src/main/java/com/google/errorprone/bugpatterns/NonApiType.java index 3433c7cc3d8..2b002417bf5 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/NonApiType.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/NonApiType.java @@ -153,6 +153,12 @@ public final class NonApiType extends BugChecker implements MethodTreeMatcher { "Prefer accepting an Iterable or Collection instead. " + STREAM_LINK, ApiElementType.PARAMETER), + // Guice + withAnyVisibility( + isExactType("com.google.inject.AbstractModule"), + "Prefer using Module instead.", + ApiElementType.ANY), + // ProtoTime withPublicVisibility( isExactType("com.google.protobuf.Duration"), diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/NonApiTypeTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/NonApiTypeTest.java index 7db66ba27bb..f5c6e052ab1 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/NonApiTypeTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/NonApiTypeTest.java @@ -365,4 +365,28 @@ public record RecordWithImmutableSet(ImmutableSet ids) { """) .doTest(); } + + @Test + public void guiceModules() { + helper + .addSourceLines( + "Test.java", + """ + import com.google.inject.AbstractModule; + import com.google.inject.Module; + + public class Test extends AbstractModule { + // BUG: Diagnostic contains: NonApiType + public AbstractModule test() { + return new AbstractModule() {}; + } + + // Exact type, no finding. + public Test test2() { + return new Test(); + } + } + """) + .doTest(); + } }