You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2017/04/11 15:17:27 UTC

svn commit: r1790991 - in /tomcat/trunk: java/org/apache/catalina/connector/CoyoteAdapter.java webapps/docs/changelog.xml

Author: markt
Date: Tue Apr 11 15:17:27 2017
New Revision: 1790991

URL: http://svn.apache.org/viewvc?rev=1790991&view=rev
Log:
Avoid potential NullPointerExceptions related to access logging during shutdown, some of which have been observed when running the unit tests.

Modified:
    tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java?rev=1790991&r1=1790990&r2=1790991&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java Tue Apr 11 15:17:27 2017
@@ -276,8 +276,9 @@ public class CoyoteAdapter implements Ad
                 if (req.getStartTime() != -1) {
                     time = System.currentTimeMillis() - req.getStartTime();
                 }
-                if (request.getMappingData().context != null) {
-                    request.getMappingData().context.logAccess(request, response, time, false);
+                Context context = request.getContext();
+                if (context != null) {
+                    context.logAccess(request, response, time, false);
                 } else {
                     log(req, res, time);
                 }
@@ -390,8 +391,16 @@ public class CoyoteAdapter implements Ad
             if (!async && postParseSuccess) {
                 // Log only if processing was invoked.
                 // If postParseRequest() failed, it has already logged it.
-                request.getMappingData().context.logAccess(request, response,
-                        System.currentTimeMillis() - req.getStartTime(), false);
+                Context context = request.getContext();
+                // If the context is null, it is likely that the endpoint was
+                // shutdown, this connection closed and the request recycled in
+                // a different thread. That thread will have updated the access
+                // log so it is OK not to update the access log here in that
+                // case.
+                if (context != null) {
+                    context.logAccess(request, response,
+                            System.currentTimeMillis() - req.getStartTime(), false);
+                }
             }
 
             req.getRequestProcessor().setWorkerThreadName(null);
@@ -446,18 +455,17 @@ public class CoyoteAdapter implements Ad
             // Log at the lowest level available. logAccess() will be
             // automatically called on parent containers.
             boolean logged = false;
-            if (request.mappingData.context != null) {
+            Context context = request.mappingData.context;
+            Host host = request.mappingData.host;
+            if (context != null) {
                 logged = true;
-                request.mappingData.context.logAccess(
-                        request, response, time, true);
-            } else if (request.mappingData.host != null) {
+                context.logAccess(request, response, time, true);
+            } else if (host != null) {
                 logged = true;
-                request.mappingData.host.logAccess(
-                        request, response, time, true);
+                host.logAccess(request, response, time, true);
             }
             if (!logged) {
-                connector.getService().getContainer().logAccess(
-                        request, response, time, true);
+                connector.getService().getContainer().logAccess(request, response, time, true);
             }
         } catch (Throwable t) {
             ExceptionUtils.handleThrowable(t);

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1790991&r1=1790990&r2=1790991&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Tue Apr 11 15:17:27 2017
@@ -85,6 +85,11 @@
         failure to load this class masking the true problem during error
         handling. (markt)
       </fix>
+      <fix>
+        Avoid potential <code>NullPointerException</code>s related to access
+        logging during shutdown, some of which have been observed when running
+        the unit tests. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Jasper">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org