From 69a02fad6bb49d857222943b54bf348703ed46ce Mon Sep 17 00:00:00 2001 From: Tim Wilson Date: Mon, 24 Jun 2024 12:57:53 -0700 Subject: [PATCH 1/2] Propagate safety through Multimap stream collectors Safety annotations were already properly propagated for `of` and `copyOf` static factories, but the stream collectors for multimaps were not properly propagating safety information. --- .../errorprone/safety/SafetyPropagationTransfer.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/baseline-error-prone/src/main/java/com/palantir/baseline/errorprone/safety/SafetyPropagationTransfer.java b/baseline-error-prone/src/main/java/com/palantir/baseline/errorprone/safety/SafetyPropagationTransfer.java index f55cd0d98..8fed46103 100644 --- a/baseline-error-prone/src/main/java/com/palantir/baseline/errorprone/safety/SafetyPropagationTransfer.java +++ b/baseline-error-prone/src/main/java/com/palantir/baseline/errorprone/safety/SafetyPropagationTransfer.java @@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSetMultimap; import com.google.common.collect.ImmutableSortedSet; +import com.google.common.collect.Multimaps; import com.google.errorprone.VisitorState; import com.google.errorprone.annotations.CheckReturnValue; import com.google.errorprone.dataflow.AccessPath; @@ -408,7 +409,16 @@ public final class SafetyPropagationTransfer implements ForwardTransferFunction< MethodMatchers.staticMethod().onClass(ImmutableMap.class.getName()).named("toImmutableMap"), MethodMatchers.staticMethod() .onClass(ImmutableBiMap.class.getName()) - .named("toImmutableBiMap")); + .named("toImmutableBiMap"), + MethodMatchers.staticMethod() + .onClass(Multimaps.class.getName()) + .namedAnyOf("toMultimap", "flatteningToMultimap"), + MethodMatchers.staticMethod() + .onClass(ImmutableListMultimap.class.getName()) + .namedAnyOf("toImmutableListMultimap", "flatteningToImmutableListMultimap"), + MethodMatchers.staticMethod() + .onClass(ImmutableSetMultimap.class.getName()) + .namedAnyOf("toImmutableSetMultimap", "flatteningToImmutableSetMultimap")); private static final Matcher COLLECT_INCLUDES_STREAM_SAFETY = Matchers.methodInvocation( MethodMatchers.instanceMethod() From 1031000b68657570084d578417e864282e474a31 Mon Sep 17 00:00:00 2001 From: svc-changelog Date: Mon, 24 Jun 2024 20:48:59 +0000 Subject: [PATCH 2/2] Add generated changelog entries --- changelog/@unreleased/pr-2827.v2.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 changelog/@unreleased/pr-2827.v2.yml diff --git a/changelog/@unreleased/pr-2827.v2.yml b/changelog/@unreleased/pr-2827.v2.yml new file mode 100644 index 000000000..b53fdf9f4 --- /dev/null +++ b/changelog/@unreleased/pr-2827.v2.yml @@ -0,0 +1,6 @@ +type: improvement +improvement: + description: Stream collectors for multimaps now properly propagate safety information + based on their key and value types. + links: + - https://github.com/palantir/gradle-baseline/pull/2827