Skip to content

Commit

Permalink
Tweak code to avoid upsetting the nullness checker.
Browse files Browse the repository at this point in the history
There are other ways to accomplish this, such as (I think) going back to the local variable that was present until cl/643464920. Let me know if you have a preference.

RELNOTES=n/a
PiperOrigin-RevId: 648355140
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Jul 1, 2024
1 parent e549ba5 commit 0a76ba8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ public Builder<K, V> put(K key, V value) {
checkEntryNotNull(key, value);
ImmutableCollection.Builder<V> valuesBuilder = ensureBuilderMapNonNull().get(key);
if (valuesBuilder == null) {
builderMap.put(key, valuesBuilder = newValueCollectionBuilder());
valuesBuilder = newValueCollectionBuilder();
ensureBuilderMapNonNull().put(key, valuesBuilder);
}
valuesBuilder.add(value);
return this;
Expand Down Expand Up @@ -224,7 +225,7 @@ public Builder<K, V> putAll(K key, Iterable<? extends V> values) {
ImmutableCollection.Builder<V> valuesBuilder = ensureBuilderMapNonNull().get(key);
if (valuesBuilder == null) {
valuesBuilder = newValueCollectionBuilder();
builderMap.put(key, valuesBuilder);
ensureBuilderMapNonNull().put(key, valuesBuilder);
}
while (valuesItr.hasNext()) {
V value = valuesItr.next();
Expand Down
5 changes: 3 additions & 2 deletions guava/src/com/google/common/collect/ImmutableMultimap.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ public Builder<K, V> put(K key, V value) {
checkEntryNotNull(key, value);
ImmutableCollection.Builder<V> valuesBuilder = ensureBuilderMapNonNull().get(key);
if (valuesBuilder == null) {
builderMap.put(key, valuesBuilder = newValueCollectionBuilder());
valuesBuilder = newValueCollectionBuilder();
ensureBuilderMapNonNull().put(key, valuesBuilder);
}
valuesBuilder.add(value);
return this;
Expand Down Expand Up @@ -226,7 +227,7 @@ public Builder<K, V> putAll(K key, Iterable<? extends V> values) {
ImmutableCollection.Builder<V> valuesBuilder = ensureBuilderMapNonNull().get(key);
if (valuesBuilder == null) {
valuesBuilder = newValueCollectionBuilder();
builderMap.put(key, valuesBuilder);
ensureBuilderMapNonNull().put(key, valuesBuilder);
}
while (valuesItr.hasNext()) {
V value = valuesItr.next();
Expand Down

0 comments on commit 0a76ba8

Please sign in to comment.