This is an automated email from the ASF dual-hosted git repository.
rmaucher pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/11.0.x by this push:
new 25a23f59ee Generalize null checks in AsyncContext
25a23f59ee is described below
commit 25a23f59ee6fa641055630b9055e226b022c580f
Author: remm <[email protected]>
AuthorDate: Wed May 20 15:44:17 2026 +0200
Generalize null checks in AsyncContext
---
.../org/apache/catalina/core/AsyncContextImpl.java | 54 ++++++++++++++++------
1 file changed, 41 insertions(+), 13 deletions(-)
diff --git a/java/org/apache/catalina/core/AsyncContextImpl.java
b/java/org/apache/catalina/core/AsyncContextImpl.java
index dc28577b98..b9154e90d9 100644
--- a/java/org/apache/catalina/core/AsyncContextImpl.java
+++ b/java/org/apache/catalina/core/AsyncContextImpl.java
@@ -111,8 +111,12 @@ public class AsyncContextImpl implements AsyncContext,
AsyncContextCallback {
log.trace(sm.getString("asyncContextImpl.fireOnComplete"));
}
List<AsyncListenerWrapper> listenersCopy = new ArrayList<>(listeners);
+ Context context = this.context;
- ClassLoader oldCL = context.bind(null);
+ ClassLoader oldCL = null;
+ if (context != null) {
+ oldCL = context.bind(null);
+ }
try {
for (AsyncListenerWrapper listener : listenersCopy) {
try {
@@ -123,9 +127,13 @@ public class AsyncContextImpl implements AsyncContext,
AsyncContextCallback {
}
}
} finally {
- context.fireRequestDestroyEvent(request.getRequest());
+ if (context != null) {
+ context.fireRequestDestroyEvent(request.getRequest());
+ }
clearServletRequestResponse();
- context.unbind(oldCL);
+ if (context != null) {
+ context.unbind(oldCL);
+ }
}
}
@@ -145,7 +153,10 @@ public class AsyncContextImpl implements AsyncContext,
AsyncContextCallback {
if (log.isTraceEnabled()) {
log.trace(sm.getString("asyncContextImpl.fireOnTimeout"));
}
- ClassLoader oldCL = context.bind(null);
+ ClassLoader oldCL = null;
+ if (context != null) {
+ oldCL = context.bind(null);
+ }
try {
List<AsyncListenerWrapper> listenersCopy = new
ArrayList<>(listeners);
for (AsyncListenerWrapper listener : listenersCopy) {
@@ -158,7 +169,9 @@ public class AsyncContextImpl implements AsyncContext,
AsyncContextCallback {
}
request.getCoyoteRequest().action(ActionCode.ASYNC_IS_TIMINGOUT, result);
} finally {
- context.unbind(oldCL);
+ if (context != null) {
+ context.unbind(oldCL);
+ }
}
}
return !result.get();
@@ -180,7 +193,8 @@ public class AsyncContextImpl implements AsyncContext,
AsyncContextCallback {
if (cpath.length() > 1) {
path = path.substring(cpath.length());
}
- if (!context.getDispatchersUseEncodedPaths()) {
+ Context context = this.context;
+ if (context == null || context.getDispatchersUseEncodedPaths()) {
path = UDecoder.URLDecode(path, StandardCharsets.UTF_8);
}
dispatch(path);
@@ -273,7 +287,12 @@ public class AsyncContextImpl implements AsyncContext,
AsyncContextCallback {
check();
T listener;
try {
- listener = (T)
context.getInstanceManager().newInstance(clazz.getName(),
clazz.getClassLoader());
+ Context context = this.context;
+ if (context != null) {
+ listener = (T)
context.getInstanceManager().newInstance(clazz.getName(),
clazz.getClassLoader());
+ } else {
+ listener = (T) Class.forName(clazz.getName(), true,
clazz.getClassLoader()).getConstructor().newInstance();
+ }
} catch (ReflectiveOperationException | NamingException e) {
throw new ServletException(e);
} catch (Exception e) {
@@ -477,10 +496,13 @@ public class AsyncContextImpl implements AsyncContext,
AsyncContextCallback {
((HttpServletResponse)
servletResponse).setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
- Host host = (Host) context.getParent();
- Valve stdHostValve = host.getPipeline().getBasic();
- if (stdHostValve instanceof StandardHostValve) {
- ((StandardHostValve) stdHostValve).throwable(request,
request.getResponse(), t);
+ Context context = this.context;
+ if (context != null) {
+ Host host = (Host) context.getParent();
+ Valve stdHostValve = host.getPipeline().getBasic();
+ if (stdHostValve instanceof StandardHostValve) {
+ ((StandardHostValve) stdHostValve).throwable(request,
request.getResponse(), t);
+ }
}
request.getCoyoteRequest().action(ActionCode.ASYNC_IS_ERROR,
result);
@@ -501,13 +523,19 @@ public class AsyncContextImpl implements AsyncContext,
AsyncContextCallback {
@Override
public void incrementInProgressAsyncCount() {
- context.incrementInProgressAsyncCount();
+ Context context = this.context;
+ if (context != null) {
+ context.incrementInProgressAsyncCount();
+ }
}
@Override
public void decrementInProgressAsyncCount() {
- context.decrementInProgressAsyncCount();
+ Context context = this.context;
+ if (context != null) {
+ context.decrementInProgressAsyncCount();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]