Skip to content

Commit 1916f61

Browse files
cpovirkGoogle Java Core Libraries
authored and
Google Java Core Libraries
committed
Document and test how ImmutableMap.toImmutableMap behaves when the mergeFunction returns null.
(The test is Google-internal for now because we're in the process of reshuffling our `Collector` tests to make them run under Android as part of #6567. Also, we skip the test under GWT+J2CL because of a bug in their implementation of `Collectors.toMap`.) This addresses the main part of #6824, but I'm keeping the bug open as a prompt to recognize our nullness annotations in the future. RELNOTES=n/a PiperOrigin-RevId: 580635720
1 parent b4433e0 commit 1916f61

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

guava/src/com/google/common/collect/ImmutableMap.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,11 @@ public abstract class ImmutableMap<K, V> implements Map<K, V>, Serializable {
9696
* and values are the result of applying the provided mapping functions to the input elements.
9797
*
9898
* <p>If the mapped keys contain duplicates (according to {@link Object#equals(Object)}), the
99-
* values are merged using the specified merging function. Entries will appear in the encounter
100-
* order of the first occurrence of the key.
99+
* values are merged using the specified merging function. If the merging function returns {@code
100+
* null}, then the collector removes the value that has been computed for the key thus far (though
101+
* future occurrences of the key would reinsert it).
102+
*
103+
* <p>Entries will appear in the encounter order of the first occurrence of the key.
101104
*
102105
* @since 21.0
103106
*/

0 commit comments

Comments
 (0)