From dc0badd6ad7d2950d4611eceb39a62303604268f Mon Sep 17 00:00:00 2001 From: Excavator Bot <33266368+svc-excavator-bot@users.noreply.github.com> Date: Wed, 12 Jan 2022 03:17:26 +0000 Subject: [PATCH] Excavator: Upgrades Baseline to the latest version (#1313) --- build.gradle | 2 +- .../metrics/annotations/AnnotationHelper.java | 16 +++++++++------- .../tritium/metrics/MetricRegistries.java | 13 ++++++++----- .../java/com/palantir/tritium/proxy/Proxies.java | 2 +- .../com/palantir/tritium/proxy/ProxiesTest.java | 9 +++++---- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/build.gradle b/build.gradle index 28b9a3ed8..474b828fa 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { dependencies { classpath 'com.google.errorprone:error_prone_core:2.10.0' - classpath 'com.palantir.baseline:gradle-baseline-java:4.56.0' + classpath 'com.palantir.baseline:gradle-baseline-java:4.57.0' classpath 'com.palantir.gradle.consistentversions:gradle-consistent-versions:2.5.0' classpath 'com.palantir.gradle.externalpublish:gradle-external-publish-plugin:1.6.0' classpath 'com.palantir.gradle.gitversion:gradle-git-version:0.12.3' diff --git a/tritium-metrics/src/main/java/com/palantir/tritium/event/metrics/annotations/AnnotationHelper.java b/tritium-metrics/src/main/java/com/palantir/tritium/event/metrics/annotations/AnnotationHelper.java index 583356052..f63c3332b 100644 --- a/tritium-metrics/src/main/java/com/palantir/tritium/event/metrics/annotations/AnnotationHelper.java +++ b/tritium-metrics/src/main/java/com/palantir/tritium/event/metrics/annotations/AnnotationHelper.java @@ -19,10 +19,12 @@ import static com.palantir.logsafe.Preconditions.checkNotNull; import com.google.common.annotations.VisibleForTesting; -import com.google.common.collect.ImmutableSet; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.Arrays; +import java.util.Collections; +import java.util.IdentityHashMap; +import java.util.Set; import javax.annotation.Nullable; public final class AnnotationHelper { @@ -88,16 +90,16 @@ public static T getMethodAnnotation( } @VisibleForTesting - private static ImmutableSet> getParentClasses(Class clazz) { - ImmutableSet.Builder> builder = ImmutableSet.builder(); - builder.add(clazz.getInterfaces()); + private static Set> getParentClasses(Class clazz) { + Set> parentClasses = Collections.newSetFromMap(new IdentityHashMap<>()); + parentClasses.addAll(Arrays.asList(clazz.getInterfaces())); Class superclass = clazz.getSuperclass(); while (superclass != null) { - builder.add(superclass.getInterfaces()); - builder.add(superclass); + parentClasses.addAll(Arrays.asList(superclass.getInterfaces())); + parentClasses.add(superclass); superclass = superclass.getSuperclass(); } - return builder.build(); + return parentClasses; } public static final class MethodSignature { diff --git a/tritium-metrics/src/main/java/com/palantir/tritium/metrics/MetricRegistries.java b/tritium-metrics/src/main/java/com/palantir/tritium/metrics/MetricRegistries.java index d61eb2de3..73f34059d 100644 --- a/tritium-metrics/src/main/java/com/palantir/tritium/metrics/MetricRegistries.java +++ b/tritium-metrics/src/main/java/com/palantir/tritium/metrics/MetricRegistries.java @@ -34,7 +34,6 @@ import com.google.common.base.Strings; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; -import com.google.common.collect.ImmutableSet; import com.palantir.logsafe.Preconditions; import com.palantir.logsafe.Safe; import com.palantir.logsafe.SafeArg; @@ -47,6 +46,9 @@ import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; +import java.util.Arrays; +import java.util.Collections; +import java.util.IdentityHashMap; import java.util.Map; import java.util.Set; import java.util.SortedMap; @@ -444,10 +446,11 @@ private static T registerOrReplace( if (existingMetric == null) { return registry.register(name, metric); } else { - Set> existingMetricInterfaces = - ImmutableSet.copyOf(existingMetric.getClass().getInterfaces()); - Set> newMetricInterfaces = - ImmutableSet.copyOf(metric.getClass().getInterfaces()); + Set> existingMetricInterfaces = Collections.newSetFromMap(new IdentityHashMap<>()); + existingMetricInterfaces.addAll( + Arrays.asList(existingMetric.getClass().getInterfaces())); + Set> newMetricInterfaces = Collections.newSetFromMap(new IdentityHashMap<>()); + newMetricInterfaces.addAll(Arrays.asList(metric.getClass().getInterfaces())); if (!existingMetricInterfaces.equals(newMetricInterfaces)) { throw new SafeIllegalArgumentException( "Metric already registered at this name that implements a different set of interfaces", diff --git a/tritium-proxy/src/main/java/com/palantir/tritium/proxy/Proxies.java b/tritium-proxy/src/main/java/com/palantir/tritium/proxy/Proxies.java index a1c888069..af83dba1d 100644 --- a/tritium-proxy/src/main/java/com/palantir/tritium/proxy/Proxies.java +++ b/tritium-proxy/src/main/java/com/palantir/tritium/proxy/Proxies.java @@ -77,7 +77,7 @@ static void checkIsInterface(Class iface) { } } - static void checkAreAllInterfaces(Set> interfaces) { + static void checkAreAllInterfaces(Iterable> interfaces) { for (Class possibleInterface : interfaces) { checkIsInterface(possibleInterface); } diff --git a/tritium-proxy/src/test/java/com/palantir/tritium/proxy/ProxiesTest.java b/tritium-proxy/src/test/java/com/palantir/tritium/proxy/ProxiesTest.java index 2ee108668..c600e94af 100644 --- a/tritium-proxy/src/test/java/com/palantir/tritium/proxy/ProxiesTest.java +++ b/tritium-proxy/src/test/java/com/palantir/tritium/proxy/ProxiesTest.java @@ -19,7 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import com.google.common.collect.ImmutableSet; +import com.google.common.collect.ImmutableList; import com.palantir.tritium.test.MoreSpecificReturn; import com.palantir.tritium.test.TestImplementation; import com.palantir.tritium.test.TestInterface; @@ -58,13 +58,14 @@ void testCheckIsInterfaceOnClass() { @Test void testCheckAreAllInterfaces() { - Proxies.checkAreAllInterfaces(ImmutableSet.of(TestInterface.class, Runnable.class, Callable.class, List.class)); + Proxies.checkAreAllInterfaces( + ImmutableList.of(TestInterface.class, Runnable.class, Callable.class, List.class)); } @Test void testCheckAreAllInterfacesWithClass() { - ImmutableSet> interfaces = - ImmutableSet.of(TestInterface.class, String.class, Runnable.class, Callable.class, List.class); + List> interfaces = + ImmutableList.of(TestInterface.class, String.class, Runnable.class, Callable.class, List.class); assertThatExceptionOfType(IllegalArgumentException.class) .isThrownBy(() -> Proxies.checkAreAllInterfaces(interfaces)); }