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

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 570f451f5e4392943e869f5b462258c2892ba77d
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Tue May 6 19:33:59 2025 +0100

    Fix a JSP/tag file compilation bug exposed by the test case for BZ 69635
    
    Tomcat's integration with the JDT compiler could not differentiate
    between the package org.apache.catalina.authenticator and the class
    org.apache.catalina.Authenticator on a case insensitive file system.
---
 java/org/apache/jasper/compiler/JDTCompiler.java | 21 +++++++++++++++------
 webapps/docs/changelog.xml                       |  5 +++++
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/java/org/apache/jasper/compiler/JDTCompiler.java 
b/java/org/apache/jasper/compiler/JDTCompiler.java
index 53b4efc076..9aa700ecc1 100644
--- a/java/org/apache/jasper/compiler/JDTCompiler.java
+++ b/java/org/apache/jasper/compiler/JDTCompiler.java
@@ -35,6 +35,7 @@ import java.util.Map;
 import java.util.StringTokenizer;
 
 import org.apache.jasper.JasperException;
+import org.apache.jasper.runtime.ExceptionUtils;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
 import org.eclipse.jdt.core.compiler.IProblem;
@@ -216,16 +217,24 @@ public class JDTCompiler extends 
org.apache.jasper.compiler.Compiler {
             }
 
             private boolean isPackage(String result) {
+                System.out.println("isPackage(\"" + result + "\")");
                 if (result.equals(targetClassName) || 
result.startsWith(targetClassName + '$')) {
                     return false;
                 }
-                String resourceName = result.replace('.', '/') + ".class";
-                try (InputStream is = 
classLoader.getResourceAsStream(resourceName)) {
-                    return is == null;
-                } catch (IOException e) {
-                    // we are here, since close on is failed. That means it 
was not null
-                    return false;
+                /*
+                 * This might look heavy-weight but, with only the ClassLoader 
API available, trying to load the
+                 * resource as a class is the only reliable way found so far 
to differentiate between a class and a
+                 * package. Other options, such as getResource(), fail for 
some edge cases on case insensitive file
+                 * systems. As this code is only called at compile time, the 
performance impact is not a significant
+                 * concern.
+                 */
+                try {
+                    classLoader.loadClass(result);
+                } catch (Throwable t) {
+                    ExceptionUtils.handleThrowable(t);
+                    return true;
                 }
+                return false;
             }
 
             @Override
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index f2c098f245..e359badf25 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -233,6 +233,11 @@
         activated via JSP servlet param useNonstandardTagOptimizations.
         (jengebr)
       </add>
+      <fix>
+        Fix an edge case compilation bug for JSP and tag files on case
+        insensitive file systems that was exposed by the test case for
+        <bug>69635</bug>. (markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Cluster">


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

Reply via email to