Skip to content

Commit

Permalink
Document and test how ImmutableMap.toImmutableMap behaves when the …
Browse files Browse the repository at this point in the history
…`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
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Nov 8, 2023
1 parent b4433e0 commit 1916f61
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions guava/src/com/google/common/collect/ImmutableMap.java
Expand Up @@ -96,8 +96,11 @@ public abstract class ImmutableMap<K, V> implements Map<K, V>, Serializable {
* and values are the result of applying the provided mapping functions to the input elements.
*
* <p>If the mapped keys contain duplicates (according to {@link Object#equals(Object)}), the
* values are merged using the specified merging function. Entries will appear in the encounter
* order of the first occurrence of the key.
* values are merged using the specified merging function. If the merging function returns {@code
* null}, then the collector removes the value that has been computed for the key thus far (though
* future occurrences of the key would reinsert it).
*
* <p>Entries will appear in the encounter order of the first occurrence of the key.
*
* @since 21.0
*/
Expand Down

0 comments on commit 1916f61

Please sign in to comment.