[tomcat] branch 9.0.x updated: Avoid NPE and keep original behaviour

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[tomcat] branch 9.0.x updated: Avoid NPE and keep original behaviour

markt
This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 273c36f  Avoid NPE and keep original behaviour
273c36f is described below

commit 273c36fd51f438305b233a008788bc92e2942cbd
Author: Mark Thomas <[hidden email]>
AuthorDate: Tue Sep 15 17:04:43 2020 +0100

    Avoid NPE and keep original behaviour
---
 .../apache/catalina/valves/PersistentValve.java    | 29 +++++++++++++---------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/java/org/apache/catalina/valves/PersistentValve.java b/java/org/apache/catalina/valves/PersistentValve.java
index df94820..5976f02 100644
--- a/java/org/apache/catalina/valves/PersistentValve.java
+++ b/java/org/apache/catalina/valves/PersistentValve.java
@@ -170,22 +170,27 @@ public class PersistentValve extends ValveBase {
                     if (manager instanceof StoreManager) {
                         Session session = manager.findSession(newsessionId);
                         Store store = ((StoreManager) manager).getStore();
-                        synchronized (session) {
-                            if (store != null && session != null && session.isValid()
-                                    && !isSessionStale(session, System.currentTimeMillis())) {
-                                store.save(session);
-                                ((StoreManager) manager).removeSuper(session);
-                                session.recycle();
-                            } else {
-                                if (container.getLogger().isDebugEnabled()) {
-                                    container.getLogger()
-                                            .debug("newsessionId store: " + store + " session: " + session + " valid: "
-                                                    + (session == null ? "N/A" : Boolean.toString(session.isValid()))
-                                                    + " stale: " + isSessionStale(session, System.currentTimeMillis()));
+                        boolean stored = false;
+                        if (session != null) {
+                            synchronized (session) {
+                                if (store != null && session.isValid() &&
+                                        !isSessionStale(session, System.currentTimeMillis())) {
+                                    store.save(session);
+                                    ((StoreManager) manager).removeSuper(session);
+                                    session.recycle();
+                                    stored = true;
                                 }
 
                             }
                         }
+                        if (!stored) {
+                            if (container.getLogger().isDebugEnabled()) {
+                                container.getLogger()
+                                        .debug("newsessionId store: " + store + " session: " + session + " valid: "
+                                                + (session == null ? "N/A" : Boolean.toString(session.isValid()))
+                                                + " stale: " + isSessionStale(session, System.currentTimeMillis()));
+                            }
+                        }
                     } else {
                         if (container.getLogger().isDebugEnabled()) {
                             container.getLogger().debug("newsessionId Manager: " +


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]