Improve handling of nulls in StandardEngine.logAccess()
authorkkolinko <kkolinko@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 2 Nov 2010 22:04:44 +0000 (22:04 +0000)
committerkkolinko <kkolinko@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 2 Nov 2010 22:04:44 +0000 (22:04 +0000)
This takes care of the case when findChild(getDefaultHost()) returns null.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1030253 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/core/StandardEngine.java

index 8eaac5c..ae9c958 100644 (file)
@@ -313,26 +313,27 @@ public class StandardEngine extends ContainerBase implements Engine {
         }
 
         if (!logged && useDefault) {
-            Host host = null;
             if (defaultAccessLog == null) {
                 // If we reached this point, this Engine can't have an AccessLog
                 // Look in the defaultHost
-                host = (Host) findChild(getDefaultHost());
-                defaultAccessLog = host.getAccessLog();
-
-                if (defaultAccessLog == null) {
-                    // Try the ROOT context of default host
-                    Context context = (Context) host.findChild("");
-                    if (context != null) {
-                        defaultAccessLog = context.getAccessLog();
-                    }
+                Host host = (Host) findChild(getDefaultHost());
+                if (host != null) {
+                    defaultAccessLog = host.getAccessLog();
 
                     if (defaultAccessLog == null) {
-                        defaultAccessLog = new NoopAccessLog();
+                        // Try the ROOT context of default host
+                        Context context = (Context) host.findChild("");
+                        if (context != null) {
+                            defaultAccessLog = context.getAccessLog();
+                        }
                     }
                 }
+
+                if (defaultAccessLog == null) {
+                    defaultAccessLog = new NoopAccessLog();
+                }
             }
-            
+
             defaultAccessLog.log(request, response, time);
         }
     }