PrintingResultHandler defensively accesses session.getAttributeNames()

Issue: SPR-16164
This commit is contained in:
Juergen Hoeller
2017-11-06 21:19:44 +01:00
parent 899994e7c1
commit 4ec60f08ad
2 changed files with 64 additions and 7 deletions

View File

@@ -59,7 +59,6 @@ public class PrintingResultHandler implements ResultHandler {
private static final String MISSING_CHARACTER_ENCODING = "<no character encoding set>";
private final ResultValuePrinter printer;
@@ -148,9 +147,14 @@ public class PrintingResultHandler implements ResultHandler {
protected final Map<String, Object> getSessionAttributes(MockHttpServletRequest request) {
HttpSession session = request.getSession(false);
return session == null ? Collections.emptyMap() :
Collections.list(session.getAttributeNames()).stream()
.collect(Collectors.toMap(n -> n, session::getAttribute));
if (session != null) {
Enumeration<String> attrNames = session.getAttributeNames();
if (attrNames != null) {
return Collections.list(attrNames).stream().
collect(Collectors.toMap(n -> n, session::getAttribute));
}
}
return Collections.emptyMap();
}
protected void printAsyncResult(MvcResult result) throws Exception {
@@ -169,7 +173,9 @@ public class PrintingResultHandler implements ResultHandler {
/**
* Print the handler.
*/
protected void printHandler(@Nullable Object handler, @Nullable HandlerInterceptor[] interceptors) throws Exception {
protected void printHandler(@Nullable Object handler, @Nullable HandlerInterceptor[] interceptors)
throws Exception {
if (handler == null) {
this.printer.printValue("Type", null);
}