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

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

commit 72c537bc9daee516ba5cf6c3baa4c96ae08e7ce9
Author: opencode <[email protected]>
AuthorDate: Wed Sep 30 13:30:21 2026 +0200

    Synchronise the check and assignment of the servlet instance in 
getServletMethods() to prevent a race which could result in a second, never 
initialised instance being retained by the wrapper
---
 java/org/apache/catalina/core/StandardWrapper.java | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/catalina/core/StandardWrapper.java 
b/java/org/apache/catalina/core/StandardWrapper.java
index 8224acff03..ad9b0e2200 100644
--- a/java/org/apache/catalina/core/StandardWrapper.java
+++ b/java/org/apache/catalina/core/StandardWrapper.java
@@ -413,7 +413,14 @@ public class StandardWrapper extends ContainerBase 
implements ServletConfig, Wra
     @Override
     public String[] getServletMethods() throws ServletException {
 
-        instance = loadServlet();
+        // Synchronise the check and the assignment of the instance to avoid a
+        // race with other threads loading the servlet which could otherwise
+        // result in a second, uninitialised instance being retained
+        synchronized (this) {
+            if (instance == null) {
+                instance = loadServlet();
+            }
+        }
 
         Class<? extends Servlet> servletClazz = instance.getClass();
         if 
(!jakarta.servlet.http.HttpServlet.class.isAssignableFrom(servletClazz)) {


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

Reply via email to