Skip to content

Commit 9803086

Browse files
eaftancushon
eaftan
authored andcommitted
Improve exemptions for CollectionUndefinedEquality.
Use SortedMap in place of TreeMap, and add SortedSet to the exemption list. Context: #1634 (comment) ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=313469240
1 parent 746c15f commit 9803086

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

core/src/main/java/com/google/errorprone/bugpatterns/collectionincompatibletype/CollectionUndefinedEquality.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ public final class CollectionUndefinedEquality extends BugChecker
5757
ImmutableList.of(
5858
"java.util.IdentityHashMap",
5959
"java.util.IdentityHashSet",
60-
"java.util.TreeMap")));
60+
"java.util.SortedMap",
61+
"java.util.SortedSet")));
6162

6263
@Override
6364
public Description matchMethodInvocation(MethodInvocationTree tree, VisitorState state) {

core/src/test/java/com/google/errorprone/bugpatterns/collectionincompatibletype/CollectionUndefinedEqualityTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,34 @@ public void treeMap_noFinding() {
7171
"}")
7272
.doTest();
7373
}
74+
75+
@Test
76+
public void sortedMap_noFinding() {
77+
helper
78+
.addSourceLines(
79+
"Test.java",
80+
"import java.util.Collection;",
81+
"import java.util.SortedMap;",
82+
"class Test {",
83+
" boolean foo(SortedMap<Collection<Integer>, Integer> xs, Collection<Integer> x) {",
84+
" return xs.containsKey(x);",
85+
" }",
86+
"}")
87+
.doTest();
88+
}
89+
90+
@Test
91+
public void sortedSet_noFinding() {
92+
helper
93+
.addSourceLines(
94+
"Test.java",
95+
"import java.util.Collection;",
96+
"import java.util.SortedSet;",
97+
"class Test {",
98+
" boolean foo(SortedSet<Collection<Integer>> xs, Collection<Integer> x) {",
99+
" return xs.contains(x);",
100+
" }",
101+
"}")
102+
.doTest();
103+
}
74104
}

0 commit comments

Comments
 (0)