Prevent StackOverflowError in AbstractJackson2HttpMessageConverter

Issue: SPR-14520
This commit is contained in:
Sebastien Deleuze 2016-08-04 11:11:15 -07:00
parent 14ae8be547
commit 7c5050cf80
2 changed files with 35 additions and 3 deletions

View File

@ -356,9 +356,13 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener
return resolvedType;
}
}
resolvedType = resolveVariable(typeVariable, contextType.getSuperType());
if (resolvedType.resolve() != null) {
return resolvedType;
ResolvableType superType = contextType.getSuperType();
if (superType != ResolvableType.NONE) {
resolvedType = resolveVariable(typeVariable, superType);
if (resolvedType.resolve() != null) {
return resolvedType;
}
}
for (ResolvableType ifc : contextType.getInterfaces()) {
resolvedType = resolveVariable(typeVariable, ifc);

View File

@ -692,6 +692,25 @@ public class RequestResponseBodyMethodProcessorTests {
assertEquals("UTF-8", this.servletResponse.getCharacterEncoding());
}
@Test // SPR-14520
public void resolveArgumentTypeVariableWithGenericInterface() throws Exception {
this.servletRequest.setContent("\"foo\"".getBytes("UTF-8"));
this.servletRequest.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
Method method = MyControllerImplementingInterface.class.getMethod("handle", Object.class);
HandlerMethod handlerMethod = new HandlerMethod(new MyControllerImplementingInterface(), method);
MethodParameter methodParameter = handlerMethod.getMethodParameters()[0];
List<HttpMessageConverter<?>> converters = new ArrayList<>();
converters.add(new MappingJackson2HttpMessageConverter());
RequestResponseBodyMethodProcessor processor = new RequestResponseBodyMethodProcessor(converters);
String value = (String)processor.readWithMessageConverters(this.request, methodParameter,
methodParameter.getGenericParameterType());
assertEquals("foo", value);
}
private void assertContentDisposition(RequestResponseBodyMethodProcessor processor,
boolean expectContentDisposition, String requestURI, String comment) throws Exception {
@ -1011,4 +1030,13 @@ public class RequestResponseBodyMethodProcessorTests {
}
}
interface MappingInterface<A> {
default A handle(@RequestBody A arg) {
return arg;
}
}
static class MyControllerImplementingInterface implements MappingInterface<String> {
}
}