This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push: new dcfda86 Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63246 dcfda86 is described below commit dcfda86093a3407ee8ad7837359d1b162134465c Author: Mark Thomas <ma...@apache.org> AuthorDate: Fri Mar 8 22:01:25 2019 +0000 Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=63246 Fix a potential NullPointerException when calling AsyncContext.dispatch() --- java/org/apache/catalina/core/AsyncContextImpl.java | 11 ++++++++--- webapps/docs/changelog.xml | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/java/org/apache/catalina/core/AsyncContextImpl.java b/java/org/apache/catalina/core/AsyncContextImpl.java index 34392e5..51198b2 100644 --- a/java/org/apache/catalina/core/AsyncContextImpl.java +++ b/java/org/apache/catalina/core/AsyncContextImpl.java @@ -180,7 +180,7 @@ public class AsyncContextImpl implements AsyncContext, AsyncContextCallback { } @Override - public void dispatch(ServletContext context, String path) { + public void dispatch(ServletContext servletContext, String path) { synchronized (asyncContextLock) { if (log.isDebugEnabled()) { logDebug("dispatch "); @@ -197,7 +197,7 @@ public class AsyncContextImpl implements AsyncContext, AsyncContextCallback { request.setAttribute(ASYNC_PATH_INFO, request.getPathInfo()); request.setAttribute(ASYNC_QUERY_STRING, request.getQueryString()); } - final RequestDispatcher requestDispatcher = context.getRequestDispatcher(path); + final RequestDispatcher requestDispatcher = servletContext.getRequestDispatcher(path); if (!(requestDispatcher instanceof AsyncDispatcher)) { throw new UnsupportedOperationException( sm.getString("asyncContextImpl.noAsyncDispatcher")); @@ -206,11 +206,16 @@ public class AsyncContextImpl implements AsyncContext, AsyncContextCallback { (AsyncDispatcher) requestDispatcher; final ServletRequest servletRequest = getRequest(); final ServletResponse servletResponse = getResponse(); + // https://bz.apache.org/bugzilla/show_bug.cgi?id=63246 + // Take a local copy as the dispatch may complete the + // request/response and that in turn may trigger recycling of this + // object before the in-progress count can be decremented + final Context context = this.context; this.dispatch = new AsyncRunnable( request, applicationDispatcher, servletRequest, servletResponse); this.request.getCoyoteRequest().action(ActionCode.ASYNC_DISPATCH, null); clearServletRequestResponse(); - this.context.decrementInProgressAsyncCount(); + context.decrementInProgressAsyncCount(); } } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index f36a7f0..3b2b00d 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -114,6 +114,10 @@ thanks to YourKit Java profiler for helping to track down the wasted memory and the root causes. (markt) </fix> + <fix> + <bug>63246</bug>: Fix a potential <code>NullPointerException</code> when + calling <code>AsyncContext.dispatch()</code>. (markt) + </fix> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org