diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ExplicitArgumentEnumeration.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ExplicitArgumentEnumeration.java index 7770efe93c..8deed25125 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ExplicitArgumentEnumeration.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/ExplicitArgumentEnumeration.java @@ -113,7 +113,7 @@ public final class ExplicitArgumentEnumeration extends BugChecker .put(OBJECT_ENUMERABLE_ASSERT, "doesNotContainAnyElementsOf", "doesNotContain") .put(OBJECT_ENUMERABLE_ASSERT, "hasSameElementsAs", "containsOnly") .put(STEP_VERIFIER_STEP, "expectNextSequence", "expectNext") - .build(); + .buildOrThrow(); /** Instantiates a new {@link ExplicitArgumentEnumeration} instance. */ public ExplicitArgumentEnumeration() {} diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonStaticImport.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonStaticImport.java index eba7253b54..aca3b6af0c 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonStaticImport.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/NonStaticImport.java @@ -182,7 +182,7 @@ private static ImmutableTable getUndesire } } - return imports.build(); + return imports.buildOrThrow(); } private static boolean shouldNotBeStaticallyImported(String type, String member) { diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/SpringMvcAnnotation.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/SpringMvcAnnotation.java index dbc27412b8..df6a19177d 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/SpringMvcAnnotation.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/bugpatterns/SpringMvcAnnotation.java @@ -54,7 +54,7 @@ public final class SpringMvcAnnotation extends BugChecker implements AnnotationT .put("PATCH", "PatchMapping") .put("POST", "PostMapping") .put("PUT", "PutMapping") - .build(); + .buildOrThrow(); /** Instantiates a new {@link SpringMvcAnnotation} instance. */ public SpringMvcAnnotation() {} diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableMapRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableMapRules.java index fa976d33dc..960837be1f 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableMapRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableMapRules.java @@ -15,6 +15,7 @@ import com.google.errorprone.refaster.annotation.Matches; import com.google.errorprone.refaster.annotation.MayOptionallyUse; import com.google.errorprone.refaster.annotation.Placeholder; +import com.google.errorprone.refaster.annotation.Repeated; import com.google.errorprone.refaster.annotation.UseImportPolicy; import java.util.Collection; import java.util.Iterator; @@ -44,12 +45,28 @@ ImmutableMap.Builder after() { } } + /** + * Prefer {@link ImmutableMap.Builder#buildOrThrow()} over the less explicit {@link + * ImmutableMap.Builder#build()}. + */ + static final class ImmutableMapBuilderBuildOrThrow { + @BeforeTemplate + ImmutableMap before(ImmutableMap.Builder builder) { + return builder.build(); + } + + @AfterTemplate + ImmutableMap after(ImmutableMap.Builder builder) { + return builder.buildOrThrow(); + } + } + /** Prefer {@link ImmutableMap#of(Object, Object)} over more contrived alternatives. */ static final class EntryToImmutableMap { @BeforeTemplate ImmutableMap before(Map.Entry entry) { return Refaster.anyOf( - ImmutableMap.builder().put(entry).build(), + ImmutableMap.builder().put(entry).buildOrThrow(), Stream.of(entry).collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue))); } @@ -104,16 +121,17 @@ ImmutableMap after( /** Prefer {@link ImmutableMap#copyOf(Iterable)} over more contrived alternatives. */ static final class EntryIterableToImmutableMap { @BeforeTemplate - ImmutableMap before(Map iterable) { + Map before(Map iterable) { return Refaster.anyOf( ImmutableMap.copyOf(iterable.entrySet()), - ImmutableMap.builder().putAll(iterable).build()); + ImmutableMap.builder().putAll(iterable).buildOrThrow(), + Map.copyOf(iterable)); } @BeforeTemplate ImmutableMap before(Iterable> iterable) { return Refaster.anyOf( - ImmutableMap.builder().putAll(iterable).build(), + ImmutableMap.builder().putAll(iterable).buildOrThrow(), Streams.stream(iterable).collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue))); } @@ -139,8 +157,6 @@ abstract static class StreamOfMapEntriesToImmutableMap { @Placeholder(allowsIdentity = true) abstract V valueFunction(@MayOptionallyUse E element); - // XXX: We could add variants in which the entry is created some other way, but we have another - // rule that covers canonicalization to `Map.entry`. @BeforeTemplate ImmutableMap before(Stream stream) { return stream @@ -224,7 +240,11 @@ ImmutableMap after(Map map) { static final class ImmutableMapOf { @BeforeTemplate Map before() { - return Refaster.anyOf(ImmutableMap.builder().build(), emptyMap(), Map.of()); + return Refaster.anyOf( + ImmutableMap.builder().buildOrThrow(), + ImmutableMap.ofEntries(), + emptyMap(), + Map.of()); } @AfterTemplate @@ -243,7 +263,10 @@ static final class ImmutableMapOf1 { @BeforeTemplate Map before(K k1, V v1) { return Refaster.anyOf( - ImmutableMap.builder().put(k1, v1).build(), singletonMap(k1, v1), Map.of(k1, v1)); + ImmutableMap.builder().put(k1, v1).buildOrThrow(), + ImmutableMap.ofEntries(Map.entry(k1, v1)), + singletonMap(k1, v1), + Map.of(k1, v1)); } @AfterTemplate @@ -261,7 +284,8 @@ ImmutableMap after(K k1, V v1) { static final class ImmutableMapOf2 { @BeforeTemplate Map before(K k1, V v1, K k2, V v2) { - return Map.of(k1, v1, k2, v2); + return Refaster.anyOf( + ImmutableMap.ofEntries(Map.entry(k1, v1), Map.entry(k2, v2)), Map.of(k1, v1, k2, v2)); } @AfterTemplate @@ -279,7 +303,9 @@ ImmutableMap after(K k1, V v1, K k2, V v2) { static final class ImmutableMapOf3 { @BeforeTemplate Map before(K k1, V v1, K k2, V v2, K k3, V v3) { - return Map.of(k1, v1, k2, v2, k3, v3); + return Refaster.anyOf( + ImmutableMap.ofEntries(Map.entry(k1, v1), Map.entry(k2, v2), Map.entry(k3, v3)), + Map.of(k1, v1, k2, v2, k3, v3)); } @AfterTemplate @@ -299,7 +325,10 @@ ImmutableMap after(K k1, V v1, K k2, V v2, K k3, V v3) { static final class ImmutableMapOf4 { @BeforeTemplate Map before(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { - return Map.of(k1, v1, k2, v2, k3, v3, k4, v4); + return Refaster.anyOf( + ImmutableMap.ofEntries( + Map.entry(k1, v1), Map.entry(k2, v2), Map.entry(k3, v3), Map.entry(k4, v4)), + Map.of(k1, v1, k2, v2, k3, v3, k4, v4)); } @AfterTemplate @@ -319,7 +348,14 @@ ImmutableMap after(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { static final class ImmutableMapOf5 { @BeforeTemplate Map before(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) { - return Map.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5); + return Refaster.anyOf( + ImmutableMap.ofEntries( + Map.entry(k1, v1), + Map.entry(k2, v2), + Map.entry(k3, v3), + Map.entry(k4, v4), + Map.entry(k5, v5)), + Map.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5)); } @AfterTemplate @@ -370,6 +406,22 @@ ImmutableMap after(ImmutableMap map) { } } + /** + * Prefer {@link ImmutableMap#ofEntries(Map.Entry[])} over alternatives that don't communicate the + * immutability of the resulting map at the type level. + */ + static final class ImmutableMapOfEntries { + @BeforeTemplate + Map before(@Repeated Map.Entry entries) { + return Map.ofEntries(entries); + } + + @AfterTemplate + ImmutableMap after(@Repeated Map.Entry entries) { + return ImmutableMap.ofEntries(entries); + } + } + // XXX: Add a rule for this: // Maps.transformValues(streamOfEntries.collect(groupBy(fun)), ImmutableMap::copyOf) // -> diff --git a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSortedMapRules.java b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSortedMapRules.java index e2cf20ef0f..2a30e31ac7 100644 --- a/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSortedMapRules.java +++ b/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/ImmutableSortedMapRules.java @@ -71,7 +71,7 @@ ImmutableSortedMap.Builder after() { static final class EmptyImmutableSortedMap, V> { @BeforeTemplate ImmutableSortedMap before() { - return ImmutableSortedMap.naturalOrder().build(); + return ImmutableSortedMap.naturalOrder().buildOrThrow(); } @AfterTemplate @@ -89,7 +89,7 @@ ImmutableSortedMap after() { static final class PairToImmutableSortedMap, V> { @BeforeTemplate ImmutableSortedMap before(K key, V value) { - return ImmutableSortedMap.naturalOrder().put(key, value).build(); + return ImmutableSortedMap.naturalOrder().put(key, value).buildOrThrow(); } @AfterTemplate @@ -105,7 +105,7 @@ static final class EntryToImmutableSortedMap, V> @BeforeTemplate ImmutableSortedMap before(Map.Entry entry) { return Refaster.anyOf( - ImmutableSortedMap.naturalOrder().put(entry).build(), + ImmutableSortedMap.naturalOrder().put(entry).buildOrThrow(), Stream.of(entry) .collect( toImmutableSortedMap(naturalOrder(), Map.Entry::getKey, Map.Entry::getValue))); @@ -126,7 +126,7 @@ ImmutableMap before(Map iterable) { return Refaster.anyOf( ImmutableSortedMap.copyOf(iterable, naturalOrder()), ImmutableSortedMap.copyOf(iterable.entrySet()), - ImmutableSortedMap.naturalOrder().putAll(iterable).build()); + ImmutableSortedMap.naturalOrder().putAll(iterable).buildOrThrow()); } @BeforeTemplate @@ -134,7 +134,7 @@ ImmutableSortedMap before( Iterable> iterable) { return Refaster.anyOf( ImmutableSortedMap.copyOf(iterable, naturalOrder()), - ImmutableSortedMap.naturalOrder().putAll(iterable).build(), + ImmutableSortedMap.naturalOrder().putAll(iterable).buildOrThrow(), Streams.stream(iterable) .collect( toImmutableSortedMap( diff --git a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java b/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java index 3f9250eb13..d7b47d307b 100644 --- a/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java +++ b/error-prone-contrib/src/test/java/tech/picnic/errorprone/refasterrules/RefasterRulesTest.java @@ -54,6 +54,7 @@ final class RefasterRulesTest { ImmutableSortedMapRules.class, ImmutableSortedMultisetRules.class, ImmutableSortedSetRules.class, + ImmutableTableRules.class, IntStreamRules.class, JUnitRules.class, JUnitToAssertJRules.class, diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestInput.java index 2302bb4c9e..7531a5f83e 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestInput.java @@ -24,9 +24,13 @@ ImmutableMap.Builder testImmutableMapBuilder() { return new ImmutableMap.Builder<>(); } + ImmutableMap testImmutableMapBuilderBuildOrThrow() { + return ImmutableMap.builder().build(); + } + ImmutableSet> testEntryToImmutableMap() { return ImmutableSet.of( - ImmutableMap.builder().put(Map.entry("foo", 1)).build(), + ImmutableMap.builder().put(Map.entry("foo", 1)).buildOrThrow(), Stream.of(Map.entry("foo", 1)) .collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue))); } @@ -51,13 +55,14 @@ ImmutableSet> testIterableToImmutableMap() { ImmutableMap.copyOf(Maps.asMap(ImmutableSet.of(10), Integer::valueOf))); } - ImmutableSet> testEntryIterableToImmutableMap() { + ImmutableSet> testEntryIterableToImmutableMap() { return ImmutableSet.of( ImmutableMap.copyOf(ImmutableMap.of("foo", 1).entrySet()), - ImmutableMap.builder().putAll(ImmutableMap.of("foo", 1)).build(), + ImmutableMap.builder().putAll(ImmutableMap.of("foo", 1)).buildOrThrow(), + Map.copyOf(ImmutableMap.of("foo", 1)), ImmutableMap.builder() .putAll(ImmutableMap.of("foo", 1).entrySet()) - .build(), + .buildOrThrow(), ImmutableMap.of("foo", 1).entrySet().stream() .collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue)), Streams.stream(Iterables.cycle(Map.entry("foo", 1))) @@ -100,32 +105,51 @@ ImmutableSet> testTransformMapValuesToImmutableMap ImmutableSet> testImmutableMapOf() { return ImmutableSet.of( - ImmutableMap.builder().build(), + ImmutableMap.builder().buildOrThrow(), + ImmutableMap.ofEntries(), Collections.emptyMap(), Map.of()); } ImmutableSet> testImmutableMapOf1() { return ImmutableSet.of( - ImmutableMap.builder().put("k1", "v1").build(), + ImmutableMap.builder().put("k1", "v1").buildOrThrow(), + ImmutableMap.ofEntries(Map.entry("k1", "v1")), Collections.singletonMap("k1", "v1"), Map.of("k1", "v1")); } - Map testImmutableMapOf2() { - return Map.of("k1", "v1", "k2", "v2"); + ImmutableSet> testImmutableMapOf2() { + return ImmutableSet.of( + ImmutableMap.ofEntries(Map.entry("k1", "v1"), Map.entry("k2", "v2")), + Map.of("k1", "v1", "k2", "v2")); } - Map testImmutableMapOf3() { - return Map.of("k1", "v1", "k2", "v2", "k3", "v3"); + ImmutableSet> testImmutableMapOf3() { + return ImmutableSet.of( + ImmutableMap.ofEntries(Map.entry("k1", "v1"), Map.entry("k2", "v2"), Map.entry("k3", "v3")), + Map.of("k1", "v1", "k2", "v2", "k3", "v3")); } - Map testImmutableMapOf4() { - return Map.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4"); + ImmutableSet> testImmutableMapOf4() { + return ImmutableSet.of( + ImmutableMap.ofEntries( + Map.entry("k1", "v1"), + Map.entry("k2", "v2"), + Map.entry("k3", "v3"), + Map.entry("k4", "v4")), + Map.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4")); } - Map testImmutableMapOf5() { - return Map.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4", "k5", "v5"); + ImmutableSet> testImmutableMapOf5() { + return ImmutableSet.of( + ImmutableMap.ofEntries( + Map.entry("k1", "v1"), + Map.entry("k2", "v2"), + Map.entry("k3", "v3"), + Map.entry("k4", "v4"), + Map.entry("k5", "v5")), + Map.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4", "k5", "v5")); } ImmutableMap testImmutableMapCopyOfMapsFilterKeys() { @@ -139,4 +163,11 @@ ImmutableMap testImmutableMapCopyOfMapsFilterValues() { .filter(entry -> entry.getValue() > 0) .collect(toImmutableMap(Map.Entry::getKey, Map.Entry::getValue)); } + + ImmutableSet> testImmutableMapOfEntries() { + return ImmutableSet.of( + Map.ofEntries(), + Map.ofEntries(Map.entry("foo", 1)), + Map.ofEntries(Map.entry("bar", 2), Map.entry("baz", 3))); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestOutput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestOutput.java index 3365f3fd59..0482e0724b 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestOutput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableMapRulesTestOutput.java @@ -24,6 +24,10 @@ ImmutableMap.Builder testImmutableMapBuilder() { return ImmutableMap.builder(); } + ImmutableMap testImmutableMapBuilderBuildOrThrow() { + return ImmutableMap.builder().buildOrThrow(); + } + ImmutableSet> testEntryToImmutableMap() { return ImmutableSet.of( ImmutableMap.of(Map.entry("foo", 1).getKey(), Map.entry("foo", 1).getValue()), @@ -46,8 +50,9 @@ ImmutableSet> testIterableToImmutableMap() { Maps.toMap(ImmutableSet.of(10), Integer::valueOf)); } - ImmutableSet> testEntryIterableToImmutableMap() { + ImmutableSet> testEntryIterableToImmutableMap() { return ImmutableSet.of( + ImmutableMap.copyOf(ImmutableMap.of("foo", 1)), ImmutableMap.copyOf(ImmutableMap.of("foo", 1)), ImmutableMap.copyOf(ImmutableMap.of("foo", 1)), ImmutableMap.copyOf(ImmutableMap.of("foo", 1).entrySet()), @@ -83,28 +88,39 @@ ImmutableSet> testTransformMapValuesToImmutableMap } ImmutableSet> testImmutableMapOf() { - return ImmutableSet.of(ImmutableMap.of(), ImmutableMap.of(), ImmutableMap.of()); + return ImmutableSet.of( + ImmutableMap.of(), ImmutableMap.of(), ImmutableMap.of(), ImmutableMap.of()); } ImmutableSet> testImmutableMapOf1() { return ImmutableSet.of( - ImmutableMap.of("k1", "v1"), ImmutableMap.of("k1", "v1"), ImmutableMap.of("k1", "v1")); + ImmutableMap.of("k1", "v1"), + ImmutableMap.of("k1", "v1"), + ImmutableMap.of("k1", "v1"), + ImmutableMap.of("k1", "v1")); } - Map testImmutableMapOf2() { - return ImmutableMap.of("k1", "v1", "k2", "v2"); + ImmutableSet> testImmutableMapOf2() { + return ImmutableSet.of( + ImmutableMap.of("k1", "v1", "k2", "v2"), ImmutableMap.of("k1", "v1", "k2", "v2")); } - Map testImmutableMapOf3() { - return ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3"); + ImmutableSet> testImmutableMapOf3() { + return ImmutableSet.of( + ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3"), + ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3")); } - Map testImmutableMapOf4() { - return ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4"); + ImmutableSet> testImmutableMapOf4() { + return ImmutableSet.of( + ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4"), + ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4")); } - Map testImmutableMapOf5() { - return ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4", "k5", "v5"); + ImmutableSet> testImmutableMapOf5() { + return ImmutableSet.of( + ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4", "k5", "v5"), + ImmutableMap.of("k1", "v1", "k2", "v2", "k3", "v3", "k4", "v4", "k5", "v5")); } ImmutableMap testImmutableMapCopyOfMapsFilterKeys() { @@ -114,4 +130,11 @@ ImmutableMap testImmutableMapCopyOfMapsFilterKeys() { ImmutableMap testImmutableMapCopyOfMapsFilterValues() { return ImmutableMap.copyOf(Maps.filterValues(ImmutableMap.of("foo", 1), v -> v > 0)); } + + ImmutableSet> testImmutableMapOfEntries() { + return ImmutableSet.of( + ImmutableMap.ofEntries(), + ImmutableMap.ofEntries(Map.entry("foo", 1)), + ImmutableMap.ofEntries(Map.entry("bar", 2), Map.entry("baz", 3))); + } } diff --git a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedMapRulesTestInput.java b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedMapRulesTestInput.java index 3dc4071701..46e9ffdaa6 100644 --- a/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedMapRulesTestInput.java +++ b/error-prone-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/ImmutableSortedMapRulesTestInput.java @@ -32,16 +32,16 @@ ImmutableSortedMap.Builder testImmutableSortedMapReverseOrderBu } ImmutableSortedMap testEmptyImmutableSortedMap() { - return ImmutableSortedMap.naturalOrder().build(); + return ImmutableSortedMap.naturalOrder().buildOrThrow(); } ImmutableSortedMap testPairToImmutableSortedMap() { - return ImmutableSortedMap.naturalOrder().put("foo", 1).build(); + return ImmutableSortedMap.naturalOrder().put("foo", 1).buildOrThrow(); } ImmutableSet> testEntryToImmutableSortedMap() { return ImmutableSet.of( - ImmutableSortedMap.naturalOrder().put(Map.entry("foo", 1)).build(), + ImmutableSortedMap.naturalOrder().put(Map.entry("foo", 1)).buildOrThrow(), Stream.of(Map.entry("foo", 1)) .collect(toImmutableSortedMap(naturalOrder(), Map.Entry::getKey, Map.Entry::getValue))); } @@ -52,10 +52,10 @@ ImmutableSet> testIterableToImmutableSortedM ImmutableSortedMap.copyOf(ImmutableSortedMap.of("foo", 1).entrySet()), ImmutableSortedMap.naturalOrder() .putAll(ImmutableSortedMap.of("foo", 1)) - .build(), + .buildOrThrow(), ImmutableSortedMap.naturalOrder() .putAll(ImmutableSortedMap.of("foo", 1).entrySet()) - .build(), + .buildOrThrow(), ImmutableSortedMap.of("foo", 1).entrySet().stream() .collect(toImmutableSortedMap(naturalOrder(), Map.Entry::getKey, Map.Entry::getValue)), Streams.stream(Iterables.cycle(Map.entry("foo", 1)))