From 9cecaa769e90ccecfbfe6c2dbdbfd2c86edc4baa Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Tue, 30 Mar 2010 08:34:29 +0000 Subject: [PATCH] SPR-7047 - XML MarshallingView assumes non-null value for object to be marshalled. --- .../web/servlet/view/xml/MarshallingView.java | 2 +- .../view/xml/MarshallingViewTests.java | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/xml/MarshallingView.java b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/xml/MarshallingView.java index aa3f396271..323a62e424 100644 --- a/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/xml/MarshallingView.java +++ b/org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/view/xml/MarshallingView.java @@ -132,7 +132,7 @@ public class MarshallingView extends AbstractView { return o; } for (Object o : model.values()) { - if (this.marshaller.supports(o.getClass())) { + if (o != null && this.marshaller.supports(o.getClass())) { return o; } } diff --git a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/view/xml/MarshallingViewTests.java b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/view/xml/MarshallingViewTests.java index 382ee08431..637b571af0 100644 --- a/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/view/xml/MarshallingViewTests.java +++ b/org.springframework.web.servlet/src/test/java/org/springframework/web/servlet/view/xml/MarshallingViewTests.java @@ -94,6 +94,27 @@ public class MarshallingViewTests { verify(marshallerMock); } + @Test + public void renderNullModelValue() throws Exception { + String modelKey = "key"; + Map model = new HashMap(); + model.put(modelKey, null); + + MockHttpServletRequest request = new MockHttpServletRequest(); + MockHttpServletResponse response = new MockHttpServletResponse(); + + replay(marshallerMock); + try { + view.render(model, request, response); + fail("ServletException expected"); + } + catch (ServletException ex) { + // expected + } + assertEquals("Invalid content length", 0, response.getContentLength()); + verify(marshallerMock); + } + @Test public void renderModelKeyUnsupported() throws Exception { Object toBeMarshalled = new Object();