From d5fd3448a9e5546cf2433389f6a2dc819563084a Mon Sep 17 00:00:00 2001 From: Bastien LEMALE Date: Mon, 12 Aug 2019 17:25:11 -0700 Subject: [PATCH] [core] Add support for ConcurrentHashMap in AbstractAsKeyOfSetOrMap Fixes #1329 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=263039480 --- .../errorprone/bugpatterns/AbstractAsKeyOfSetOrMap.java | 1 + .../errorprone/bugpatterns/ArrayAsKeyOfSetOrMapTest.java | 7 +++++++ .../errorprone/bugpatterns/ProtosAsKeyOfSetOrMapTest.java | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/AbstractAsKeyOfSetOrMap.java b/core/src/main/java/com/google/errorprone/bugpatterns/AbstractAsKeyOfSetOrMap.java index 38b7b0451d9..dddaf91e5d0 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/AbstractAsKeyOfSetOrMap.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/AbstractAsKeyOfSetOrMap.java @@ -67,6 +67,7 @@ public abstract class AbstractAsKeyOfSetOrMap extends BugChecker .onClass("com.google.common.collect.Maps") .named("newLinkedHashMap"), Matchers.constructor().forClass("java.util.LinkedHashMap"), + Matchers.constructor().forClass("java.util.concurrent.ConcurrentHashMap"), MethodMatchers.staticMethod() .onClass("com.google.common.collect.HashBiMap") .named("create")); diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ArrayAsKeyOfSetOrMapTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ArrayAsKeyOfSetOrMapTest.java index 1b278366316..fd258f00dad 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ArrayAsKeyOfSetOrMapTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ArrayAsKeyOfSetOrMapTest.java @@ -48,6 +48,7 @@ public void positive() { "import java.util.Set;", "import java.util.Map;", "import java.util.LinkedHashMap;", + "import java.util.concurrent.ConcurrentHashMap;", "import com.google.common.collect.Sets;", "import com.google.common.collect.Maps;", "import com.google.common.collect.HashMultiset;", @@ -94,6 +95,9 @@ public void positive() { " LinkedHashMap testLinkedHashMap" + "= new LinkedHashMap();", " // BUG: Diagnostic contains: ArrayAsKeyOfSetOrMap", + " ConcurrentHashMap testConcurrentHashMap" + + "= new ConcurrentHashMap();", + " // BUG: Diagnostic contains: ArrayAsKeyOfSetOrMap", " HashMultiset testHashMultiSet = HashMultiset.create();", " // BUG: Diagnostic contains: ArrayAsKeyOfSetOrMap", " LinkedHashMultiset testLinkedHashMultiSet" @@ -112,6 +116,7 @@ public void negative() { "import java.util.Set;", "import java.util.Map;", "import java.util.LinkedHashMap;", + "import java.util.concurrent.ConcurrentHashMap;", "import com.google.common.collect.Sets;", "import com.google.common.collect.Maps;", "import java.util.HashMap;", @@ -147,6 +152,8 @@ public void negative() { " HashBiMap testHashBiMap = HashBiMap.create();", " LinkedHashMap testLinkedHashMap" + "= new LinkedHashMap();", + " ConcurrentHashMap testConcurrentHashMap" + + "= new ConcurrentHashMap();", " HashMultiset testHashMultiSet = HashMultiset.create();", " LinkedHashMultiset testLinkedHashMultiSet" + "= LinkedHashMultiset.create();", diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ProtosAsKeyOfSetOrMapTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ProtosAsKeyOfSetOrMapTest.java index f6eaf0a388a..53702a5dbb0 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ProtosAsKeyOfSetOrMapTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/ProtosAsKeyOfSetOrMapTest.java @@ -46,6 +46,7 @@ public void positive() { "import java.util.HashMap;", "import java.util.HashSet;", "import java.util.Collection;", + "import java.util.concurrent.ConcurrentHashMap;", "import com.google.common.collect.Sets;", "import com.google.common.collect.Maps;", "import com.google.common.collect.HashMultiset;", @@ -97,6 +98,9 @@ public void positive() { " LinkedHashMap testLinkedHashMap" + "= new LinkedHashMap();", " // BUG: Diagnostic contains: ProtosAsKeyOfSetOrMap", + " ConcurrentHashMap testConcurrentHashMap" + + "= new ConcurrentHashMap();", + " // BUG: Diagnostic contains: ProtosAsKeyOfSetOrMap", " LinkedHashMultiset testLinkedHashMultiSet" + "= LinkedHashMultiset.create();", " // BUG: Diagnostic contains: ProtosAsKeyOfSetOrMap", @@ -115,6 +119,7 @@ public void negative() { "import java.util.Set;", "import java.util.Map;", "import java.util.LinkedHashMap;", + "import java.util.concurrent.ConcurrentHashMap;", "import com.google.common.collect.Sets;", "import com.google.common.collect.Maps;", "import java.util.HashMap;", @@ -150,6 +155,8 @@ public void negative() { " HashBiMap testHashBiMap = HashBiMap.create();", " LinkedHashMap testLinkedHashMap" + "= new LinkedHashMap();", + " ConcurrentHashMap testConcurrentHashMap" + + "= new ConcurrentHashMap();", " HashMultiset testHashMultiSet = HashMultiset.create();", " LinkedHashMultiset testLinkedHashMultiSet" + "= LinkedHashMultiset.create();",