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

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

commit c912cdd937896b121a57f9deb94204c2bb2dd5f9
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 3381f8ccb1..4a298aabe5 100644
--- a/java/org/apache/catalina/core/StandardWrapper.java
+++ b/java/org/apache/catalina/core/StandardWrapper.java
@@ -496,7 +496,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 
(!javax.servlet.http.HttpServlet.class.isAssignableFrom(servletClazz)) {


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

Reply via email to