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 275ac79  Fix NPE if exception occurs during destruction of Servlet - 
BZ 65940
275ac79 is described below

commit 275ac79558379108cce4907abd9cfe6599b21d19
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Mar 9 09:22:34 2022 +0000

    Fix NPE if exception occurs during destruction of Servlet - BZ 65940
    
    https://bz.apache.org/bugzilla/show_bug.cgi?id=65940
    Also includes a trivial optimisation
---
 java/org/apache/catalina/core/StandardWrapper.java | 4 ++--
 webapps/docs/changelog.xml                         | 4 ++++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/java/org/apache/catalina/core/StandardWrapper.java 
b/java/org/apache/catalina/core/StandardWrapper.java
index 6d41a5f..4a73bbe 100644
--- a/java/org/apache/catalina/core/StandardWrapper.java
+++ b/java/org/apache/catalina/core/StandardWrapper.java
@@ -1328,7 +1328,6 @@ public class StandardWrapper extends ContainerBase
             } catch (Throwable t) {
                 t = ExceptionUtils.unwrapInvocationTargetException(t);
                 ExceptionUtils.handleThrowable(t);
-                instance = null;
                 instancePool = null;
                 nInstances = 0;
                 fireContainerEvent("unload", this);
@@ -1357,12 +1356,13 @@ public class StandardWrapper extends ContainerBase
                         }
                     }
                 }
+                instance = null;
+                instanceInitialized = false;
             }
         }
 
         // Deregister the destroyed instance
         instance = null;
-        instanceInitialized = false;
 
         if (isJspServlet && jspMonitorON != null ) {
             Registry.getRegistry(null, null).unregisterComponent(jspMonitorON);
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 9f28ce2..c42d010 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -117,6 +117,10 @@
         original request cannot be mapped to a context. This typically happens
         when no ROOT context is defined. Pull request by elkman. (markt)
       </fix>
+      <fix>
+        <bug>65940</bug>: Fix <code>NullPointerException</code> if an exception
+        occurs during the destruction of a Servlet. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">

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

Reply via email to