-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Description
Randy Cramp opened SPR-16164 and commented
After migrating from Spring 4.3.12, we're now seeing NullPointerExceptions as a result of the code for #19755. During debugging, we see that the attributes field on the session is null. As a result, the Collections.list(session.getAttributeNames)) throws the NPE.
Partial stacktrace:
java.lang.NullPointerException
at java.util.Collections.list(Collections.java:5239)
at org.springframework.test.web.servlet.result.PrintingResultHandler.getSessionAttributes(PrintingResultHandler.java:152)
at org.springframework.test.web.servlet.result.PrintingResultHandler.printRequest(PrintingResultHandler.java:120)
at org.springframework.test.web.servlet.result.PrintingResultHandler.handle(PrintingResultHandler.java:87)
at org.springframework.test.web.servlet.MockMvc$1.andDo(MockMvc.java:184)
Code snippet:
MockHttpSession session = Mockito.mock(MockHttpSession.class);
MockHttpServletRequestBuilder requestBuilder = MockMvcRequestBuilders.post("/dummy-url")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.header(HEADER_ENDPOINT, endpointUrl)
.content(someContent);
requestBuilder.session(session);
MockMvc mockMvc = MockMvcBuilders.standaloneSetup(endpointController).build();
mockMvc.perform(requestBuilder)
.andDo(print())
.andExpect(status().isOk());
Affects: 5.0.1
Reference URL: #19755
Issue Links:
- Print session attributes in PrintingResultHandler in Spring MVC Test [SPR-15189] #19755 Print session attributes in PrintingResultHandler in Spring MVC Test
Referenced from: commits 4ec60f0