Consistent handling of empty List entries in LinkedMultiValueMap
Closes gh-22912
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -81,7 +81,7 @@ public class LinkedMultiValueMap<K, V> implements MultiValueMap<K, V>, Serializa
|
||||
@Nullable
|
||||
public V getFirst(K key) {
|
||||
List<V> values = this.targetMap.get(key);
|
||||
return (values != null ? values.get(0) : null);
|
||||
return (values != null && !values.isEmpty() ? values.get(0) : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -118,7 +118,11 @@ public class LinkedMultiValueMap<K, V> implements MultiValueMap<K, V>, Serializa
|
||||
@Override
|
||||
public Map<K, V> toSingleValueMap() {
|
||||
LinkedHashMap<K, V> singleValueMap = new LinkedHashMap<>(this.targetMap.size());
|
||||
this.targetMap.forEach((key, value) -> singleValueMap.put(key, value.get(0)));
|
||||
this.targetMap.forEach((key, values) -> {
|
||||
if (values != null && !values.isEmpty()) {
|
||||
singleValueMap.put(key, values.get(0));
|
||||
}
|
||||
});
|
||||
return singleValueMap;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user