From 1d6efed16186315bf3f2b56f9c68db195f42a654 Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Fri, 6 Jan 2023 16:07:11 +0100 Subject: [PATCH] BadImport: Add `newInstance` to `BAD_STATIC_IDENTIFIERS` --- .../errorprone/bugpatterns/BadImport.java | 1 + .../errorprone/bugpatterns/BadImportTest.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) 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 512f343ffa29..2bc16f6b51c2 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 0a8b57605ee6..875dc7944c1c 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:", + " newInstance(BugChecker.class, getClass());", + "}") + .doTest(); + } + @Test public void msg() { compilationTestHelper