diff --git a/spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java b/spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java index 8c158ecf0fc4..3ba6b0eda11b 100644 --- a/spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java +++ b/spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java @@ -59,7 +59,7 @@ public MultiValueMapAdapter(Map> targetMap) { @Nullable public V getFirst(K key) { List values = this.targetMap.get(key); - return (values != null && !values.isEmpty() ? values.get(0) : null); + return (!CollectionUtils.isEmpty(values) ? values.get(0) : null); } @Override @@ -95,7 +95,7 @@ public void setAll(Map values) { public Map toSingleValueMap() { Map singleValueMap = CollectionUtils.newLinkedHashMap(this.targetMap.size()); this.targetMap.forEach((key, values) -> { - if (values != null && !values.isEmpty()) { + if (!CollectionUtils.isEmpty(values)) { singleValueMap.put(key, values.get(0)); } }); diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/MultipartControllerTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/MultipartControllerTests.java index 78b9cb2748ca..f65342982090 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/MultipartControllerTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/client/standalone/MultipartControllerTests.java @@ -36,6 +36,7 @@ import org.springframework.stereotype.Controller; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.test.web.servlet.client.MockMvcWebTestClient; +import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -271,7 +272,7 @@ public String processMultipartFileArray(@RequestParam(required = false) Multipar public String processMultipartFileList(@RequestParam(required = false) List file, @RequestPart(required = false) Map json) throws IOException { - if (file != null && !file.isEmpty()) { + if (!CollectionUtils.isEmpty(file)) { byte[] content = file.get(0).getBytes(); assertThat(file.get(1).getBytes()).isEqualTo(content); } diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/MultipartControllerTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/MultipartControllerTests.java index 8026ea48cf37..178f5ded8a65 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/MultipartControllerTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/samples/standalone/MultipartControllerTests.java @@ -39,6 +39,7 @@ import org.springframework.stereotype.Controller; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder; +import org.springframework.util.CollectionUtils; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; @@ -271,7 +272,7 @@ public String processMultipartFileArray(@RequestParam(required = false) Multipar public String processMultipartFileList(@RequestParam(required = false) List file, @RequestPart(required = false) Map json) throws IOException { - if (file != null && !file.isEmpty()) { + if (!CollectionUtils.isEmpty(file)) { byte[] content = file.get(0).getBytes(); assertThat(file.get(1).getBytes()).isEqualTo(content); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java index 10b46f1923ba..4bfe88e362bf 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/AbstractFlashMapManager.java @@ -220,7 +220,7 @@ public final void saveOutputFlashMap(FlashMap flashMap, HttpServletRequest reque @Nullable private String decodeAndNormalizePath(@Nullable String path, HttpServletRequest request) { - if (path != null && !path.isEmpty()) { + if (StringUtils.hasLength(path)) { path = getUrlPathHelper().decodeRequestString(request, path); if (path.charAt(0) != '/') { String requestUri = getUrlPathHelper().getRequestUri(request);