Browse Source

Fix single-check idiom in UnmodifiableMultiValueMap

Read the respective fields only once in the values(), entrySet(), and
keySet() methods.

Closes gh-35822

Signed-off-by: Patrick Strawderman <pstrawderman@netflix.com>
pull/35843/head
Patrick Strawderman 1 month ago committed by Sam Brannen
parent
commit
3b6be3d4d3
  1. 24
      spring-core/src/main/java/org/springframework/util/UnmodifiableMultiValueMap.java

24
spring-core/src/main/java/org/springframework/util/UnmodifiableMultiValueMap.java

@ -141,26 +141,32 @@ final class UnmodifiableMultiValueMap<K,V> implements MultiValueMap<K,V>, Serial @@ -141,26 +141,32 @@ final class UnmodifiableMultiValueMap<K,V> implements MultiValueMap<K,V>, Serial
@Override
public Set<K> keySet() {
if (this.keySet == null) {
this.keySet = Collections.unmodifiableSet(this.delegate.keySet());
Set<K> keySet = this.keySet;
if (keySet == null) {
keySet = Collections.unmodifiableSet(this.delegate.keySet());
this.keySet = keySet;
}
return this.keySet;
return keySet;
}
@Override
public Set<Entry<K, List<V>>> entrySet() {
if (this.entrySet == null) {
this.entrySet = new UnmodifiableEntrySet<>(this.delegate.entrySet());
Set<Entry<K, List<V>>> entrySet = this.entrySet;
if (entrySet == null) {
entrySet = new UnmodifiableEntrySet<>(this.delegate.entrySet());
this.entrySet = entrySet;
}
return this.entrySet;
return entrySet;
}
@Override
public Collection<List<V>> values() {
if (this.values == null) {
this.values = new UnmodifiableValueCollection<>(this.delegate.values());
Collection<List<V>> values = this.values;
if (values == null) {
values = new UnmodifiableValueCollection<>(this.delegate.values());
this.values = values;
}
return this.values;
return values;
}
// unsupported

Loading…
Cancel
Save