From e7a53e37fb1a0131f2c753fd83c1d161e21b1105 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 2 Jul 2016 13:02:22 +0200 Subject: [PATCH] Avoid stateful MethodParameter nesting level changes in MVC processing --- ...stractMessageConverterMethodProcessor.java | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java index b2a37b077ab..5c0efcd7990 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2016 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. @@ -30,6 +30,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.core.MethodParameter; +import org.springframework.core.ResolvableType; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpOutputMessage; @@ -67,11 +68,6 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe private static final UrlPathHelper DECODING_URL_PATH_HELPER = new UrlPathHelper(); - static { - RAW_URL_PATH_HELPER.setRemoveSemicolonContent(false); - RAW_URL_PATH_HELPER.setUrlDecode(false); - } - /* Extensions associated with the built-in message converters */ private static final Set WHITELISTED_EXTENSIONS = new HashSet(Arrays.asList( "txt", "text", "yml", "properties", "csv", @@ -81,6 +77,10 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe private static final Set WHITELISTED_MEDIA_BASE_TYPES = new HashSet( Arrays.asList("audio", "image", "video")); + static { + RAW_URL_PATH_HELPER.setRemoveSemicolonContent(false); + RAW_URL_PATH_HELPER.setUrlDecode(false); + } private final ContentNegotiationManager contentNegotiationManager; @@ -266,19 +266,16 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe } /** - * Return the generic type of the {@code returnType} (or of the nested type if it is - * a {@link HttpEntity}). + * Return the generic type of the {@code returnType} (or of the nested type + * if it is an {@link HttpEntity}). */ private Type getGenericType(MethodParameter returnType) { - Type type; if (HttpEntity.class.isAssignableFrom(returnType.getParameterType())) { - returnType.increaseNestingLevel(); - type = returnType.getNestedGenericParameterType(); + return ResolvableType.forType(returnType.getGenericParameterType()).getGeneric(0).getType(); } else { - type = returnType.getGenericParameterType(); + return returnType.getGenericParameterType(); } - return type; } /**