Skip to content

Commit

Permalink
Store.load() implementations assume (in places) that getManager().get…
Browse files Browse the repository at this point in the history
…Context() 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

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1723736 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
markt-asf committed Jan 8, 2016
1 parent 283a9b6 commit 2cd5fd9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
19 changes: 10 additions & 9 deletions java/org/apache/catalina/session/FileStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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
Expand Down Expand Up @@ -217,9 +218,12 @@ public Session load(String id) throws ClassNotFoundException, IOException {
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;
Expand All @@ -228,10 +232,7 @@ public Session load(String id) throws ClassNotFoundException, IOException {
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();
}
Expand All @@ -247,8 +248,8 @@ public Session load(String id) throws ClassNotFoundException, IOException {
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 {
Expand Down
21 changes: 10 additions & 11 deletions java/org/apache/catalina/session/JDBCStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
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;

/**
Expand Down Expand Up @@ -595,7 +596,8 @@ public Session load(String id) throws ClassNotFoundException, IOException {
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;
Expand All @@ -620,10 +622,7 @@ public Session load(String id) throws ClassNotFoundException, IOException {
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();
}
Expand All @@ -634,22 +633,22 @@ public Session load(String id) throws ClassNotFoundException, IOException {
}
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 {
Expand Down

0 comments on commit 2cd5fd9

Please sign in to comment.