Skip to content

Commit fee259a

Browse files
committed
WebAsyncManager defensively ignores attribute type mismatch
Issue: SPR-15709 (cherry picked from commit c4694c3)
1 parent 016b7d7 commit fee259a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncUtils.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,7 +44,11 @@ public abstract class WebAsyncUtils {
4444
* found, create and associate it with the request.
4545
*/
4646
public static WebAsyncManager getAsyncManager(ServletRequest servletRequest) {
47-
WebAsyncManager asyncManager = (WebAsyncManager) servletRequest.getAttribute(WEB_ASYNC_MANAGER_ATTRIBUTE);
47+
WebAsyncManager asyncManager = null;
48+
Object asyncManagerAttr = servletRequest.getAttribute(WEB_ASYNC_MANAGER_ATTRIBUTE);
49+
if (asyncManagerAttr instanceof WebAsyncManager) {
50+
asyncManager = (WebAsyncManager) asyncManagerAttr;
51+
}
4852
if (asyncManager == null) {
4953
asyncManager = new WebAsyncManager();
5054
servletRequest.setAttribute(WEB_ASYNC_MANAGER_ATTRIBUTE, asyncManager);
@@ -58,7 +62,11 @@ public static WebAsyncManager getAsyncManager(ServletRequest servletRequest) {
5862
*/
5963
public static WebAsyncManager getAsyncManager(WebRequest webRequest) {
6064
int scope = RequestAttributes.SCOPE_REQUEST;
61-
WebAsyncManager asyncManager = (WebAsyncManager) webRequest.getAttribute(WEB_ASYNC_MANAGER_ATTRIBUTE, scope);
65+
WebAsyncManager asyncManager = null;
66+
Object asyncManagerAttr = webRequest.getAttribute(WEB_ASYNC_MANAGER_ATTRIBUTE, scope);
67+
if (asyncManagerAttr instanceof WebAsyncManager) {
68+
asyncManager = (WebAsyncManager) asyncManagerAttr;
69+
}
6270
if (asyncManager == null) {
6371
asyncManager = new WebAsyncManager();
6472
webRequest.setAttribute(WEB_ASYNC_MANAGER_ATTRIBUTE, asyncManager, scope);

0 commit comments

Comments
 (0)