-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Closed
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchesAn issue that has been backported to maintenance branchestype: bugA general bugA general bug
Milestone
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);
Metadata
Metadata
Assignees
Labels
in: coreIssues in core modules (aop, beans, core, context, expression)Issues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchesAn issue that has been backported to maintenance branchestype: bugA general bugA general bug