diff --git a/spring-core/src/main/java/org/springframework/util/CollectionUtils.java b/spring-core/src/main/java/org/springframework/util/CollectionUtils.java index 2060af6adf8..09fddf0084c 100644 --- a/spring-core/src/main/java/org/springframework/util/CollectionUtils.java +++ b/spring-core/src/main/java/org/springframework/util/CollectionUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -418,7 +418,7 @@ public abstract class CollectionUtils { @Override public V getFirst(K key) { List values = this.map.get(key); - return (values != null ? values.get(0) : null); + return (values != null && !values.isEmpty() ? values.get(0) : null); } @Override @@ -439,7 +439,10 @@ public abstract class CollectionUtils { public Map toSingleValueMap() { LinkedHashMap singleValueMap = new LinkedHashMap(this.map.size()); for (Entry> entry : map.entrySet()) { - singleValueMap.put(entry.getKey(), entry.getValue().get(0)); + List values = entry.getValue(); + if (values != null && !values.isEmpty()) { + singleValueMap.put(entry.getKey(), values.get(0)); + } } return singleValueMap; } @@ -506,10 +509,7 @@ public abstract class CollectionUtils { @Override public boolean equals(Object other) { - if (this == other) { - return true; - } - return this.map.equals(other); + return (this == other || this.map.equals(other)); } @Override diff --git a/spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java b/spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java index 1b3932d4836..19756d309c7 100644 --- a/spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java +++ b/spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -216,8 +216,8 @@ public class LinkedCaseInsensitiveMap implements Map, Serializable } @Override - public boolean equals(Object obj) { - return this.targetMap.equals(obj); + public boolean equals(Object other) { + return (this == other || this.targetMap.equals(other)); } @Override diff --git a/spring-core/src/main/java/org/springframework/util/LinkedMultiValueMap.java b/spring-core/src/main/java/org/springframework/util/LinkedMultiValueMap.java index bbb34c35728..be71c48cd78 100644 --- a/spring-core/src/main/java/org/springframework/util/LinkedMultiValueMap.java +++ b/spring-core/src/main/java/org/springframework/util/LinkedMultiValueMap.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -208,8 +208,8 @@ public class LinkedMultiValueMap implements MultiValueMap, Serializa } @Override - public boolean equals(Object obj) { - return this.targetMap.equals(obj); + public boolean equals(Object other) { + return (this == other || this.targetMap.equals(other)); } @Override