tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1723736 - in /tomcat/trunk/java/org/apache/catalina/session: FileStore.java JDBCStore.java
Date Fri, 08 Jan 2016 15:15:13 GMT
Author: markt
Date: Fri Jan  8 15:15:13 2016
New Revision: 1723736

URL: http://svn.apache.org/viewvc?rev=1723736&view=rev
Log:
Store.load() implementations assume (in places) that getManager().getContext() always returns
a non-null and we haven't had reports of NPEs so make the assumption consistently throughout
the method.
Add a local reference to the Context's logger to shorten some of the logging lines

Modified:
    tomcat/trunk/java/org/apache/catalina/session/FileStore.java
    tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java

Modified: tomcat/trunk/java/org/apache/catalina/session/FileStore.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/FileStore.java?rev=1723736&r1=1723735&r2=1723736&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/FileStore.java (original)
+++ tomcat/trunk/java/org/apache/catalina/session/FileStore.java Fri Jan  8 15:15:13 2016
@@ -33,6 +33,7 @@ import org.apache.catalina.Context;
 import org.apache.catalina.Loader;
 import org.apache.catalina.Session;
 import org.apache.catalina.util.CustomObjectInputStream;
+import org.apache.juli.logging.Log;
 
 /**
  * Concrete implementation of the <b>Store</b> interface that utilizes
@@ -217,9 +218,12 @@ public final class FileStore extends Sto
         if (!file.exists()) {
             return null;
         }
-        if (manager.getContext().getLogger().isDebugEnabled()) {
-            manager.getContext().getLogger().debug(sm.getString(getStoreName()+".loading",
-                             id, file.getAbsolutePath()));
+
+        Context context = getManager().getContext();
+        Log contextLog = context.getLogger();
+
+        if (contextLog.isDebugEnabled()) {
+            contextLog.debug(sm.getString(getStoreName()+".loading", id, file.getAbsolutePath()));
         }
 
         ObjectInputStream ois = null;
@@ -228,10 +232,7 @@ public final class FileStore extends Sto
         ClassLoader oldThreadContextCL = Thread.currentThread().getContextClassLoader();
         try (FileInputStream fis = new FileInputStream(file.getAbsolutePath());
                 BufferedInputStream bis = new BufferedInputStream(fis)) {
-            Context context = manager.getContext();
-            if (context != null) {
-                loader = context.getLoader();
-            }
+            loader = context.getLoader();
             if (loader != null) {
                 classLoader = loader.getClassLoader();
             }
@@ -247,8 +248,8 @@ public final class FileStore extends Sto
             session.setManager(manager);
             return session;
         } catch (FileNotFoundException e) {
-            if (manager.getContext().getLogger().isDebugEnabled()) {
-                manager.getContext().getLogger().debug("No persisted data file found");
+            if (contextLog.isDebugEnabled()) {
+                contextLog.debug("No persisted data file found");
             }
             return null;
         } finally {

Modified: tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java?rev=1723736&r1=1723735&r2=1723736&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java (original)
+++ tomcat/trunk/java/org/apache/catalina/session/JDBCStore.java Fri Jan  8 15:15:13 2016
@@ -43,6 +43,7 @@ import org.apache.catalina.LifecycleExce
 import org.apache.catalina.Loader;
 import org.apache.catalina.Session;
 import org.apache.catalina.util.CustomObjectInputStream;
+import org.apache.juli.logging.Log;
 import org.apache.tomcat.util.ExceptionUtils;
 
 /**
@@ -595,7 +596,8 @@ public class JDBCStore extends StoreBase
         ClassLoader classLoader = null;
         ObjectInputStream ois = null;
         BufferedInputStream bis = null;
-        org.apache.catalina.Context context = manager.getContext();
+        org.apache.catalina.Context context = getManager().getContext();
+        Log contextLog = context.getLogger();
 
         synchronized (this) {
             int numberOfTries = 2;
@@ -620,10 +622,7 @@ public class JDBCStore extends StoreBase
                     try (ResultSet rst = preparedLoadSql.executeQuery()) {
                         if (rst.next()) {
                             bis = new BufferedInputStream(rst.getBinaryStream(2));
-
-                            if (context != null) {
-                                loader = context.getLoader();
-                            }
+                            loader = context.getLoader();
                             if (loader != null) {
                                 classLoader = loader.getClassLoader();
                             }
@@ -634,22 +633,22 @@ public class JDBCStore extends StoreBase
                             }
                             ois = new CustomObjectInputStream(bis, classLoader);
 
-                            if (manager.getContext().getLogger().isDebugEnabled()) {
-                                manager.getContext().getLogger().debug(sm.getString(getStoreName()
+ ".loading",
-                                        id, sessionTable));
+                            if (contextLog.isDebugEnabled()) {
+                                contextLog.debug(
+                                        sm.getString(getStoreName() + ".loading", id, sessionTable));
                             }
 
                             _session = (StandardSession) manager.createEmptySession();
                             _session.readObjectData(ois);
                             _session.setManager(manager);
-                          } else if (manager.getContext().getLogger().isDebugEnabled()) {
-                            manager.getContext().getLogger().debug(getStoreName() + ": No
persisted data object found");
+                        } else if (context.getLogger().isDebugEnabled()) {
+                            contextLog.debug(getStoreName() + ": No persisted data object
found");
                         }
                         // Break out after the finally block
                         numberOfTries = 0;
                     }
                 } catch (SQLException e) {
-                    manager.getContext().getLogger().error(sm.getString(getStoreName() +
".SQLException", e));
+                    contextLog.error(sm.getString(getStoreName() + ".SQLException", e));
                     if (dbConnection != null)
                         close(dbConnection);
                 } finally {



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


Mime
View raw message