Skip to content

Commit 7e6e113

Browse files
klueverError Prone Team
authored andcommitted
PUBLIC: Discourage static importing values().
PiperOrigin-RevId: 833969838
1 parent cc1e3bf commit 7e6e113

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

core/src/main/java/com/google/errorprone/bugpatterns/BadImport.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,20 @@ public class BadImport extends BugChecker implements ImportTreeMatcher {
8787

8888
private static final ImmutableSet<String> BAD_STATIC_IDENTIFIERS =
8989
ImmutableSet.of(
90+
// keep-sorted start
91+
"INSTANCE",
9092
"builder",
91-
"create",
9293
"copyOf",
94+
"create",
9395
"from",
9496
"getDefaultInstance",
95-
"INSTANCE",
9697
"newBuilder",
9798
"newInstance",
9899
"of",
99-
"valueOf");
100+
"valueOf",
101+
"values"
102+
// keep-sorted end
103+
);
100104

101105
private static final MultiMatcher<Tree, AnnotationTree> HAS_TYPE_USE_ANNOTATION =
102106
annotations(AT_LEAST_ONE, (t, state) -> isTypeAnnotation(t));

core/src/test/java/com/google/errorprone/bugpatterns/BadImportTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,26 @@ class Test {
731731
.doTest();
732732
}
733733

734+
@Test
735+
public void enumValues() {
736+
compilationTestHelper
737+
.addSourceLines(
738+
"Test.java",
739+
"""
740+
import static java.util.concurrent.TimeUnit.values;
741+
742+
import java.util.concurrent.TimeUnit;
743+
744+
class Test {
745+
void foo() {
746+
// BUG: Diagnostic contains: TimeUnit.values()
747+
TimeUnit[] timeUnits = values();
748+
}
749+
}
750+
""")
751+
.doTest();
752+
}
753+
734754
@Test
735755
public void doesNotMatchProtos() {
736756
compilationTestHelper

0 commit comments

Comments
 (0)