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


The following commit(s) were added to refs/heads/main by this push:
     new 91278e6794 Fix BZ 69635 - add support to ImportHandler for resolving 
inner classes
91278e6794 is described below

commit 91278e6794b073af33574aade2d82386722685d4
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Apr 4 17:17:39 2025 +0100

    Fix BZ 69635 - add support to ImportHandler for resolving inner classes
    
    https://bz.apache.org/bugzilla/show_bug.cgi?id=69635
---
 java/jakarta/el/ImportHandler.java     | 12 ++++++++++++
 test/jakarta/el/TestImportHandler.java | 17 +++++++++++++++++
 test/org/apache/el/TestELInJsp.java    | 10 ++++++++++
 test/webapp/bug6nnnn/bug69635.jsp      | 18 ++++++++++++++++++
 webapps/docs/changelog.xml             |  4 ++++
 5 files changed, 61 insertions(+)

diff --git a/java/jakarta/el/ImportHandler.java 
b/java/jakarta/el/ImportHandler.java
index ac2e9e492a..f3fc447742 100644
--- a/java/jakarta/el/ImportHandler.java
+++ b/java/jakarta/el/ImportHandler.java
@@ -398,6 +398,18 @@ public class ImportHandler {
                 clazzes.put(name, clazz);
                 return clazz;
             }
+            // Might be an inner class
+            StringBuilder sb = new StringBuilder(className);
+            int replacementPosition = sb.lastIndexOf(".");
+            while (replacementPosition > -1) {
+                sb.setCharAt(replacementPosition, '$');
+                clazz = findClass(sb.toString(), true);
+                if (clazz != null) {
+                    clazzes.put(name, clazz);
+                    return clazz;
+                }
+                replacementPosition = sb.lastIndexOf(".", replacementPosition);
+            }
         }
 
         // Search the package imports - note there may be multiple matches
diff --git a/test/jakarta/el/TestImportHandler.java 
b/test/jakarta/el/TestImportHandler.java
index db4bbf5cd9..ef3e533e4d 100644
--- a/test/jakarta/el/TestImportHandler.java
+++ b/test/jakarta/el/TestImportHandler.java
@@ -21,6 +21,7 @@ import java.util.ArrayList;
 import org.junit.Assert;
 import org.junit.Test;
 
+import org.apache.catalina.authenticator.DigestAuthenticator;
 import org.apache.tomcat.util.res.StringManager;
 
 public class TestImportHandler {
@@ -265,4 +266,20 @@ public class TestImportHandler {
 
         importHandler.resolveClass("Foo");
     }
+
+
+    /**
+     * Support for inner classes.
+     * <p>
+     * https://bz.apache.org/bugzilla/show_bug.cgi?id=69635
+     */
+    @Test
+    public void testResolveInnerClass() {
+        ImportHandler importHandler = new ImportHandler();
+
+        
importHandler.importClass("org.apache.catalina.authenticator.DigestAuthenticator.AuthDigest");
+        Class<?> clazz = importHandler.resolveClass("AuthDigest");
+
+        Assert.assertEquals(DigestAuthenticator.AuthDigest.class, clazz);
+    }
 }
diff --git a/test/org/apache/el/TestELInJsp.java 
b/test/org/apache/el/TestELInJsp.java
index 4c8bfb0661..10fa44ba3f 100644
--- a/test/org/apache/el/TestELInJsp.java
+++ b/test/org/apache/el/TestELInJsp.java
@@ -508,6 +508,16 @@ public class TestELInJsp extends TomcatBaseTest {
     }
 
 
+    @Test
+    public void testBug69635() throws Exception {
+        getTomcatInstanceTestWebapp(true, true);
+
+        ByteChunk res = getUrl("http://localhost:"; + getPort() + 
"/test/bug6nnnn/bug69635.jsp");
+        String result = res.toString();
+        assertEcho(result, "01-3");
+    }
+
+
     // Assertion for text contained with <p></p>, e.g. printed by tags:echo
     private static void assertEcho(String result, String expected) {
         Assert.assertTrue(result, result.indexOf("<p>" + expected + "</p>") > 
0);
diff --git a/test/webapp/bug6nnnn/bug69635.jsp 
b/test/webapp/bug6nnnn/bug69635.jsp
new file mode 100644
index 0000000000..2d2a2411a5
--- /dev/null
+++ b/test/webapp/bug6nnnn/bug69635.jsp
@@ -0,0 +1,18 @@
+<%--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+--%>
+<%@page 
import="org.apache.catalina.authenticator.DigestAuthenticator.AuthDigest"%>
+<p>01-${ AuthDigest.values().length }</p>
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index a91d666576..3bd2b09515 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -199,6 +199,10 @@
         21 being the minimum Java version required for Tomcat 12. (markt)
       </update>
       <!-- Entries for backport and removal before 12.0.0-M1 below this line 
-->
+      <fix>
+        <bug>69635</bug>: Add support to <code>jakarta.el.ImportHandler</code>
+        for resolving inner classes. (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