diff --git a/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java b/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java index 08fad1c431..4a88a27081 100644 --- a/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java +++ b/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java @@ -167,6 +167,7 @@ public abstract class MimeTypeUtils { private static volatile Random random; static { + // Not using "parseMimeType" to avoid static init cost ALL = new MimeType("*", "*"); APPLICATION_JSON = new MimeType("application", "json"); APPLICATION_OCTET_STREAM = new MimeType("application", "octet-stream"); diff --git a/spring-web/src/main/java/org/springframework/http/MediaType.java b/spring-web/src/main/java/org/springframework/http/MediaType.java index 78db60611b..0875862b49 100644 --- a/spring-web/src/main/java/org/springframework/http/MediaType.java +++ b/spring-web/src/main/java/org/springframework/http/MediaType.java @@ -323,6 +323,7 @@ public class MediaType extends MimeType implements Serializable { static { + // Not using "valueOf' to avoid static init cost ALL = new MediaType("*", "*"); APPLICATION_ATOM_XML = new MediaType("application", "atom+xml"); APPLICATION_FORM_URLENCODED = new MediaType("application", "x-www-form-urlencoded"); @@ -552,6 +553,7 @@ public class MediaType extends MimeType implements Serializable { if (!StringUtils.hasLength(mediaTypes)) { return Collections.emptyList(); } + // Avoid using java.util.stream.Stream in hot paths List tokenizedTypes = MimeTypeUtils.tokenize(mediaTypes); List result = new ArrayList<>(tokenizedTypes.size()); for (String type : tokenizedTypes) {