https://bz.apache.org/bugzilla/show_bug.cgi?id=69615
Bug ID: 69615 Summary: Potential Regression in Tomcat 9.0.97+(Including Tomcat 10 and Tomcat 11) — NoClassDefFoundError for Dynamically Loaded Classes Product: Tomcat 9 Version: 9.0.97 Hardware: PC OS: All Status: NEW Severity: regression Priority: P2 Component: Catalina Assignee: dev@tomcat.apache.org Reporter: dushyant.shinde...@gmail.com Target Milestone: ----- We would like to report a potential regression issue observed in Tomcat 9.0.97+, including Tomcat 10 and Tomcat 11, that appears to break expected behaviour regarding dynamically loaded JARs. ## Issue Description: Our application is a WAR-based deployment running on Tomcat 11 with Java 21. The application allows importing extensions (JARs) at runtime, which are dynamically loaded using URLClassLoader. In Tomcat 9.0.96 and earlier, dynamically loaded classes were immediately recognized without issues. However, starting from Tomcat 9.0.97, we encountered the following error when attempting to access classes from these dynamically loaded JARs: java.lang.NoClassDefFoundError: org/apache/logging/log4j/spi/ExtendedLogger ## Steps to Reproduce: 1. Deploy a WAR-based application on Tomcat 9.0.97+. 2. Dynamically load a JAR (e.g. log4j-api-2.17.1.jar) using the following code: URLClassLoader webappClassLoader = (URLClassLoader) Thread.currentThread().getContextClassLoader(); Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); method.setAccessible(true); method.invoke(webappClassLoader, new Object[]{jarUrl}); 3. Attempt to access a class from the dynamically loaded JAR, such as org.apache.logging.log4j.spi.ExtendedLogger. 4. Observe the NoClassDefFoundError exception despite the JAR being successfully loaded. ## Findings: • Debugging confirmed that the JAR was successfully loaded by the classloader. • Classes like org.apache.logging.log4j.LogManager and org.apache.logging.log4j.Logger were accessible, but org.apache.logging.log4j.spi.ExtendedLogger still resulted in a NoClassDefFoundError. • Restarting Tomcat resolves the issue, confirming it’s related to Tomcat's internal caching. ## Root Cause Analysis: This issue appears to be related to the notFoundClassResourceCacheSize caching mechanism introduced in Tomcat 9.0.97. • If a class is requested before its JAR is loaded, Tomcat caches it as "not found." • Even after dynamically loading the JAR, Tomcat does not reattempt the class lookup, causing a NoClassDefFoundError. • This behaviour differs from Tomcat 9.0.96 and earlier, where dynamically loaded JARs were recognized immediately without requiring a server restart. ## Impact: This caching behaviour is problematic for applications that rely on runtime JAR loading and introduces unexpected behaviour that breaks compatibility with previous Tomcat versions. Given that Tomcat has historically maintained backward compatibility, this change could be considered a regression. ## Request: We believe this behaviour deviates from expected functionality and may impact other applications that rely on dynamic class loading. We kindly request that the Tomcat team review this behaviour and consider addressing it in future releases to restore compatibility. -- You are receiving this mail because: You are the assignee for the bug. --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org