This is an automated email from the ASF dual-hosted git repository. rmaucher pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 659da056d4a437d5cd53831cb70b401db8e29b6d 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 b960de5db8..5f522e1d2f 100644 --- a/java/org/apache/catalina/core/StandardWrapper.java +++ b/java/org/apache/catalina/core/StandardWrapper.java @@ -420,7 +420,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]
