From fee259a3c5150521a5add6a7ec0d3ab24fe16551 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 30 Jun 2017 01:53:30 +0200 Subject: [PATCH] WebAsyncManager defensively ignores attribute type mismatch Issue: SPR-15709 (cherry picked from commit c4694c3) --- .../web/context/request/async/WebAsyncUtils.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncUtils.java b/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncUtils.java index 8690866ebd..9a0f115de9 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncUtils.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/WebAsyncUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,7 +44,11 @@ public abstract class WebAsyncUtils { * found, create and associate it with the request. */ public static WebAsyncManager getAsyncManager(ServletRequest servletRequest) { - WebAsyncManager asyncManager = (WebAsyncManager) servletRequest.getAttribute(WEB_ASYNC_MANAGER_ATTRIBUTE); + WebAsyncManager asyncManager = null; + Object asyncManagerAttr = servletRequest.getAttribute(WEB_ASYNC_MANAGER_ATTRIBUTE); + if (asyncManagerAttr instanceof WebAsyncManager) { + asyncManager = (WebAsyncManager) asyncManagerAttr; + } if (asyncManager == null) { asyncManager = new WebAsyncManager(); servletRequest.setAttribute(WEB_ASYNC_MANAGER_ATTRIBUTE, asyncManager); @@ -58,7 +62,11 @@ public abstract class WebAsyncUtils { */ public static WebAsyncManager getAsyncManager(WebRequest webRequest) { int scope = RequestAttributes.SCOPE_REQUEST; - WebAsyncManager asyncManager = (WebAsyncManager) webRequest.getAttribute(WEB_ASYNC_MANAGER_ATTRIBUTE, scope); + WebAsyncManager asyncManager = null; + Object asyncManagerAttr = webRequest.getAttribute(WEB_ASYNC_MANAGER_ATTRIBUTE, scope); + if (asyncManagerAttr instanceof WebAsyncManager) { + asyncManager = (WebAsyncManager) asyncManagerAttr; + } if (asyncManager == null) { asyncManager = new WebAsyncManager(); webRequest.setAttribute(WEB_ASYNC_MANAGER_ATTRIBUTE, asyncManager, scope);