Closed
Description
If You create MultiValueMap
via MultiValueMapAdapter
, and value list is empty, call of method getFirst
fail on IndexOutOfBounds
exception:
private static class MultiValueMapAdapter<K, V> implements MultiValueMap<K, V>, Serializable {
private final Map<K, List<V>> map;
public MultiValueMapAdapter(Map<K, List<V>> map) {
Assert.notNull(map, "'map' must not be null");
this.map = map;
}
@Override
@Nullable
public V getFirst(K key) {
List<V> values = this.map.get(key);
return (values != null ? values.get(0) : null);
}
Good solution is:
return (values != null && !values.isEmpty() ? values.get(0) : null);