11/*
2- * Copyright 2002-2016 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.
3232 */
3333public abstract class WebAsyncUtils {
3434
35- public static final String WEB_ASYNC_MANAGER_ATTRIBUTE = WebAsyncManager .class .getName () + ".WEB_ASYNC_MANAGER" ;
35+ public static final String WEB_ASYNC_MANAGER_ATTRIBUTE =
36+ WebAsyncManager .class .getName () + ".WEB_ASYNC_MANAGER" ;
3637
3738
3839 /**
3940 * Obtain the {@link WebAsyncManager} for the current request, or if not
4041 * found, create and associate it with the request.
4142 */
4243 public static WebAsyncManager getAsyncManager (ServletRequest servletRequest ) {
43- WebAsyncManager asyncManager = (WebAsyncManager ) servletRequest .getAttribute (WEB_ASYNC_MANAGER_ATTRIBUTE );
44+ WebAsyncManager asyncManager = null ;
45+ Object asyncManagerAttr = servletRequest .getAttribute (WEB_ASYNC_MANAGER_ATTRIBUTE );
46+ if (asyncManagerAttr instanceof WebAsyncManager ) {
47+ asyncManager = (WebAsyncManager ) asyncManagerAttr ;
48+ }
4449 if (asyncManager == null ) {
4550 asyncManager = new WebAsyncManager ();
4651 servletRequest .setAttribute (WEB_ASYNC_MANAGER_ATTRIBUTE , asyncManager );
@@ -54,7 +59,11 @@ public static WebAsyncManager getAsyncManager(ServletRequest servletRequest) {
5459 */
5560 public static WebAsyncManager getAsyncManager (WebRequest webRequest ) {
5661 int scope = RequestAttributes .SCOPE_REQUEST ;
57- WebAsyncManager asyncManager = (WebAsyncManager ) webRequest .getAttribute (WEB_ASYNC_MANAGER_ATTRIBUTE , scope );
62+ WebAsyncManager asyncManager = null ;
63+ Object asyncManagerAttr = webRequest .getAttribute (WEB_ASYNC_MANAGER_ATTRIBUTE , scope );
64+ if (asyncManagerAttr instanceof WebAsyncManager ) {
65+ asyncManager = (WebAsyncManager ) asyncManagerAttr ;
66+ }
5867 if (asyncManager == null ) {
5968 asyncManager = new WebAsyncManager ();
6069 webRequest .setAttribute (WEB_ASYNC_MANAGER_ATTRIBUTE , asyncManager , scope );
0 commit comments