diff --git a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/trace/servlet/TraceableHttpServletRequest.java b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/trace/servlet/TraceableHttpServletRequest.java index eb74733ff5a..b6ea52577ec 100644 --- a/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/trace/servlet/TraceableHttpServletRequest.java +++ b/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/web/trace/servlet/TraceableHttpServletRequest.java @@ -19,7 +19,7 @@ package org.springframework.boot.actuate.web.trace.servlet; import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; +import java.util.Collections; import java.util.Enumeration; import java.util.LinkedHashMap; import java.util.List; @@ -85,17 +85,9 @@ final class TraceableHttpServletRequest implements TraceableRequest { Enumeration names = this.request.getHeaderNames(); while (names.hasMoreElements()) { String name = names.nextElement(); - headers.put(name, toList(this.request.getHeaders(name))); + headers.put(name, Collections.list(this.request.getHeaders(name))); } return headers; } - private List toList(Enumeration enumeration) { - List list = new ArrayList<>(); - while (enumeration.hasMoreElements()) { - list.add(enumeration.nextElement()); - } - return list; - } - } diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/classloader/RestartClassLoaderTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/classloader/RestartClassLoaderTests.java index be50d95ffec..8327df6993e 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/classloader/RestartClassLoaderTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/classloader/RestartClassLoaderTests.java @@ -23,7 +23,7 @@ import java.io.InputStream; import java.net.URL; import java.net.URLClassLoader; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; +import java.util.Collections; import java.util.Enumeration; import java.util.List; import java.util.jar.JarOutputStream; @@ -212,13 +212,8 @@ public class RestartClassLoaderTests { } private List toList(Enumeration enumeration) { - List list = new ArrayList<>(); - if (enumeration != null) { - while (enumeration.hasMoreElements()) { - list.add(enumeration.nextElement()); - } - } - return list; + return (enumeration != null) ? Collections.list(enumeration) + : Collections.emptyList(); } }