From e3703b7603b824e190852d6cd16f257866565718 Mon Sep 17 00:00:00 2001 From: ghm Date: Thu, 14 Apr 2022 04:02:06 -0700 Subject: [PATCH] Remove ProtosAsKeyOfSetOrMap. This was added a fair while ago, and not enabled. PiperOrigin-RevId: 441720080 --- .../bugpatterns/ProtosAsKeyOfSetOrMap.java | 48 ----- .../scanner/BuiltInCheckerSuppliers.java | 2 - .../ProtosAsKeyOfSetOrMapTest.java | 167 ------------------ 3 files changed, 217 deletions(-) delete mode 100644 core/src/main/java/com/google/errorprone/bugpatterns/ProtosAsKeyOfSetOrMap.java delete mode 100644 core/src/test/java/com/google/errorprone/bugpatterns/ProtosAsKeyOfSetOrMapTest.java diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/ProtosAsKeyOfSetOrMap.java b/core/src/main/java/com/google/errorprone/bugpatterns/ProtosAsKeyOfSetOrMap.java deleted file mode 100644 index 0dd0975fe08..00000000000 --- a/core/src/main/java/com/google/errorprone/bugpatterns/ProtosAsKeyOfSetOrMap.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2018 The Error Prone Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.errorprone.bugpatterns; - -import static com.google.errorprone.BugPattern.SeverityLevel.WARNING; - -import com.google.errorprone.BugPattern; -import com.google.errorprone.VisitorState; -import com.google.errorprone.suppliers.Supplier; -import com.google.errorprone.util.ASTHelpers; -import com.sun.tools.javac.code.Type; - -/** - * Check for usage of {@code Set} or {@code Map}. - * - * @author seibelsabrina@google.com (Sabrina Seibel) - */ -@BugPattern( - summary = - "Protos should not be used as a key to a map, in a set, or in a contains method on a " - + "descendant of a collection. Protos have non deterministic ordering and proto " - + "equality is deep, which is a performance issue.", - severity = WARNING) -public class ProtosAsKeyOfSetOrMap extends AbstractAsKeyOfSetOrMap { - - @Override - protected boolean isBadType(Type type, VisitorState state) { - return ASTHelpers.isSubtype(type, COM_GOOGLE_PROTOBUF_GENERATEDMESSAGE.get(state), state); - } - - private static final Supplier COM_GOOGLE_PROTOBUF_GENERATEDMESSAGE = - VisitorState.memoize( - state -> state.getTypeFromString("com.google.protobuf.GeneratedMessage")); -} diff --git a/core/src/main/java/com/google/errorprone/scanner/BuiltInCheckerSuppliers.java b/core/src/main/java/com/google/errorprone/scanner/BuiltInCheckerSuppliers.java index 780593ddd83..11070872e3c 100644 --- a/core/src/main/java/com/google/errorprone/scanner/BuiltInCheckerSuppliers.java +++ b/core/src/main/java/com/google/errorprone/scanner/BuiltInCheckerSuppliers.java @@ -281,7 +281,6 @@ import com.google.errorprone.bugpatterns.ProtoStringFieldReferenceEquality; import com.google.errorprone.bugpatterns.ProtoTruthMixedDescriptors; import com.google.errorprone.bugpatterns.ProtocolBufferOrdinal; -import com.google.errorprone.bugpatterns.ProtosAsKeyOfSetOrMap; import com.google.errorprone.bugpatterns.PublicApiNamedStreamShouldReturnStream; import com.google.errorprone.bugpatterns.RandomCast; import com.google.errorprone.bugpatterns.RandomModInteger; @@ -1068,7 +1067,6 @@ public static ScannerSupplier errorChecks() { PrimitiveArrayPassedToVarargsMethod.class, PrivateConstructorForNoninstantiableModule.class, PrivateConstructorForUtilityClass.class, - ProtosAsKeyOfSetOrMap.class, PublicApiNamedStreamShouldReturnStream.class, QualifierWithTypeUse.class, RedundantOverride.class, diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/ProtosAsKeyOfSetOrMapTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/ProtosAsKeyOfSetOrMapTest.java deleted file mode 100644 index 53702a5dbb0..00000000000 --- a/core/src/test/java/com/google/errorprone/bugpatterns/ProtosAsKeyOfSetOrMapTest.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright 2018 The Error Prone Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.errorprone.bugpatterns; - -import com.google.errorprone.CompilationTestHelper; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** - * {@link ProtosAsKeyOfSetOrMap}Test - * - * @author seibelsabrina@google.com (Sabrina Seibel) - */ -@RunWith(JUnit4.class) -public final class ProtosAsKeyOfSetOrMapTest { - - private final CompilationTestHelper compilationHelper = - CompilationTestHelper.newInstance(ProtosAsKeyOfSetOrMap.class, getClass()); - - @Ignore("b/74365407 test proto sources are broken") - @Test - public void positive() { - compilationHelper - .addSourceLines( - "Test.java", - "import java.util.Arrays;", - "import java.util.Set;", - "import java.util.Map;", - "import java.util.LinkedHashMap;", - "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;", - "import com.google.common.collect.LinkedHashMultiset;", - "import com.google.common.collect.HashBiMap;", - "import com.google.common.collect.HashMultimap;", - "import com.google.common.collect.LinkedHashMultimap;", - "import com.google.common.collect.ArrayListMultimap;", - "import com.google.common.collect.LinkedListMultimap;", - "import com.google.errorprone.bugpatterns.proto.ProtoTest.TestProtoMessage;", - "import com.google.protobuf.InvalidProtocolBufferException;", - "import com.google.protobuf.ByteString;", - "class Test {", - " void f(Collection x, TestProtoMessage m)" - + " throws InvalidProtocolBufferException {", - " // BUG: Diagnostic contains: ProtosAsKeyOfSetOrMap", - " Map testNewMap = Maps.newHashMap();", - " // BUG: Diagnostic contains: ProtosAsKeyOfSetOrMap", - " Set testNewSet = Sets.newHashSet();", - " // BUG: Diagnostic contains: ProtosAsKeyOfSetOrMap", - " HashMap testNewHashMap = Maps.newHashMap();", - " // BUG: Diagnostic contains: ProtosAsKeyOfSetOrMap", - " HashSet testNewHashSet = Sets.newHashSet();", - " // BUG: Diagnostic contains: ProtosAsKeyOfSetOrMap", - " Map testMap = new HashMap();", - " // BUG: Diagnostic contains: ProtosAsKeyOfSetOrMap", - " Set testSet = new HashSet();", - " // BUG: Diagnostic contains: ProtosAsKeyOfSetOrMap", - " HashMap testHashMap = new HashMap();", - " // BUG: Diagnostic contains: ProtosAsKeyOfSetOrMap", - " HashSet testHashSet = new HashSet();", - " // BUG: Diagnostic contains: ProtosAsKeyOfSetOrMap", - " HashMultimap testHashMultimap =" - + "HashMultimap.create();", - " // BUG: Diagnostic contains: ProtosAsKeyOfSetOrMap", - " ArrayListMultimap testArrayListMultimap" - + " = ArrayListMultimap.create();", - " // BUG: Diagnostic contains: ProtosAsKeyOfSetOrMap", - " LinkedHashMultimap testLinkedHashMultimap" - + "= LinkedHashMultimap.create();", - " // BUG: Diagnostic contains: ProtosAsKeyOfSetOrMap", - " LinkedListMultimap testLinkedListMultimap" - + "= LinkedListMultimap.create();", - " // BUG: Diagnostic contains: ProtosAsKeyOfSetOrMap", - " HashBiMap testHashBiMap = HashBiMap.create();", - " // BUG: Diagnostic contains: ProtosAsKeyOfSetOrMap", - " LinkedHashMap testLinkedHashMap" - + "= new LinkedHashMap();", - " // BUG: Diagnostic contains: ProtosAsKeyOfSetOrMap", - " ConcurrentHashMap testConcurrentHashMap" - + "= new ConcurrentHashMap();", - " // BUG: Diagnostic contains: ProtosAsKeyOfSetOrMap", - " LinkedHashMultiset testLinkedHashMultiSet" - + "= LinkedHashMultiset.create();", - " // BUG: Diagnostic contains: ProtosAsKeyOfSetOrMap", - " HashMultiset testHashMultiSet = HashMultiset.create();", - " }", - "}") - .doTest(); - } - - @Test - public void negative() { - compilationHelper - .addSourceLines( - "Test.java", - "import java.util.Arrays;", - "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;", - "import java.util.HashSet;", - "import java.util.TreeSet;", - "import com.google.common.collect.HashMultiset;", - "import com.google.common.collect.LinkedHashMultiset;", - "import com.google.common.collect.HashBiMap;", - "import com.google.common.collect.HashMultimap;", - "import com.google.common.collect.LinkedHashMultimap;", - "import com.google.common.collect.ArrayListMultimap;", - "import com.google.common.collect.LinkedListMultimap;", - "import com.google.common.collect.Ordering;", - "class Test {", - " public static void main(String[] args) {", - " Map testMap = new HashMap();", - " Set testSet = new HashSet();", - " HashMap testHashMap = new HashMap();", - " HashSet testHashSet = new HashSet();", - " Set testSet2 = new HashSet();", - " Map testMap2 = new HashMap();", - " Map mapFromMethod = Maps.newHashMap();", - " Set setFromMethod = Sets.newHashSet();", - " Set thisShouldWork = new TreeSet" - + "(Ordering.natural().lexicographical().onResultOf(Arrays::asList));", - " HashMultimap testHashMultimap = HashMultimap.create();", - " ArrayListMultimap testArrayListMultimap" - + " = ArrayListMultimap.create();", - " LinkedHashMultimap testLinkedHashMultimap" - + "= LinkedHashMultimap.create();", - " LinkedListMultimap testLinkedListMultimap" - + "= LinkedListMultimap.create();", - " HashBiMap testHashBiMap = HashBiMap.create();", - " LinkedHashMap testLinkedHashMap" - + "= new LinkedHashMap();", - " ConcurrentHashMap testConcurrentHashMap" - + "= new ConcurrentHashMap();", - " HashMultiset testHashMultiSet = HashMultiset.create();", - " LinkedHashMultiset testLinkedHashMultiSet" - + "= LinkedHashMultiset.create();", - " }", - "}") - .doTest(); - } -}