diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/BadImport.java b/core/src/main/java/com/google/errorprone/bugpatterns/BadImport.java index 512f343ffa2..2bc16f6b51c 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/BadImport.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/BadImport.java @@ -82,6 +82,7 @@ public class BadImport extends BugChecker implements ImportTreeMatcher { "getDefaultInstance", "INSTANCE", "newBuilder", + "newInstance", "of", "valueOf"); diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/BadImportTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/BadImportTest.java index 0a8b57605ee..cc048e48141 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/BadImportTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/BadImportTest.java @@ -44,6 +44,23 @@ public void positive_static_simpleCase() { .doTest(); } + @Test + public void positive_identifiers() { + compilationTestHelper + .addSourceLines( + "Test.java", + "import static com.google.errorprone.CompilationTestHelper.newInstance;", + "import com.google.errorprone.CompilationTestHelper;", + "import com.google.errorprone.bugpatterns.BugChecker;", + "", + "class Test {", + " private final CompilationTestHelper compilationTestHelper =", + " // BUG: Diagnostic contains: CompilationTestHelper.newInstance", + " newInstance(BugChecker.class, getClass());", + "}") + .doTest(); + } + @Test public void msg() { compilationTestHelper