This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push: new 1ffc2c22e9 Fix BZ 69635 - add support to ImportHandler for resolving inner classes 1ffc2c22e9 is described below commit 1ffc2c22e9566daf0efec12ee2a01d752d296159 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/javax/el/ImportHandler.java | 12 ++++++++++++ test/javax/el/TestImportHandler.java | 17 +++++++++++++++++ test/org/apache/el/TestELInJsp.java | 10 ++++++++++ test/webapp/bug6nnnn/bug69635.jsp | 18 ++++++++++++++++++ webapps/docs/changelog.xml | 8 ++++++++ 5 files changed, 65 insertions(+) diff --git a/java/javax/el/ImportHandler.java b/java/javax/el/ImportHandler.java index ee8fa97899..bc540850b4 100644 --- a/java/javax/el/ImportHandler.java +++ b/java/javax/el/ImportHandler.java @@ -401,6 +401,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/javax/el/TestImportHandler.java b/test/javax/el/TestImportHandler.java index 271c39e5a4..57ed7b1ae2 100644 --- a/test/javax/el/TestImportHandler.java +++ b/test/javax/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 e36f939af5..d1ccefa636 100644 --- a/test/org/apache/el/TestELInJsp.java +++ b/test/org/apache/el/TestELInJsp.java @@ -507,6 +507,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 9c1da0842f..3a97a3159e 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -119,6 +119,14 @@ </fix> </changelog> </subsection> + <subsection name="Jasper"> + <changelog> + <fix> + <bug>69635</bug>: Add support to <code>jakarta.el.ImportHandler</code> + for resolving inner classes. (markt) + </fix> + </changelog> + </subsection> <subsection name="Other"> <changelog> <update> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org