Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Printing of session with null attributes results in NullPointerException [SPR-16164] #20712

Closed
spring-projects-issues opened this issue Nov 6, 2017 · 0 comments
Assignees
Labels
in: test Issues in the test module type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 6, 2017

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:

Referenced from: commits 4ec60f0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants