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

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


The following commit(s) were added to refs/heads/8.5.x by this push:
     new c6bf5a415e Fix BZ 66441 - Make imports of static fields in JSPs 
visible to EL
c6bf5a415e is described below

commit c6bf5a415e83233e645d5e7dfb35ebe61cc811fe
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Feb 1 14:49:27 2023 +0000

    Fix BZ 66441 - Make imports of static fields in JSPs visible to EL
    
    https://bz.apache.org/bugzilla/show_bug.cgi?id=66441
---
 .../org/apache/jasper/runtime/PageContextImpl.java |  7 +++-
 .../javax/servlet/jsp/el/TestImportELResolver.java | 39 ++++++++++++++++++++++
 test/webapp/bug6nnnn/bug66441.jsp                  | 23 +++++++++++++
 webapps/docs/changelog.xml                         |  4 +++
 4 files changed, 72 insertions(+), 1 deletion(-)

diff --git a/java/org/apache/jasper/runtime/PageContextImpl.java 
b/java/org/apache/jasper/runtime/PageContextImpl.java
index d4bf054b29..3034ab2023 100644
--- a/java/org/apache/jasper/runtime/PageContextImpl.java
+++ b/java/org/apache/jasper/runtime/PageContextImpl.java
@@ -957,7 +957,12 @@ public class PageContextImpl extends PageContext {
                 Set<String> classImports = ((JspSourceImports) 
servlet).getClassImports();
                 if (classImports != null) {
                     for (String classImport : classImports) {
-                        ih.importClass(classImport);
+                        if (classImport.startsWith("static ")) {
+                            classImport = classImport.substring(7);
+                            ih.importStatic(classImport);
+                        } else {
+                            ih.importClass(classImport);
+                        }
                     }
                 }
             }
diff --git a/test/javax/servlet/jsp/el/TestImportELResolver.java 
b/test/javax/servlet/jsp/el/TestImportELResolver.java
new file mode 100644
index 0000000000..f065822ec6
--- /dev/null
+++ b/test/javax/servlet/jsp/el/TestImportELResolver.java
@@ -0,0 +1,39 @@
+/*
+ * 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.
+ */
+package javax.servlet.jsp.el;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.catalina.startup.TomcatBaseTest;
+import org.apache.tomcat.util.buf.ByteChunk;
+
+public class TestImportELResolver extends TomcatBaseTest {
+
+    // https://bz.apache.org/bugzilla/show_bug.cgi?id=66441
+    @Test
+    public void testImportStaticFields() throws Exception {
+        getTomcatInstanceTestWebapp(false, true);
+
+        ByteChunk res = getUrl("http://localhost:"; + getPort() + 
"/test/bug6nnnn/bug66441.jsp");
+
+        String result = res.toString();
+
+        Assert.assertTrue(result.contains("EL  - Long min value is 
-9223372036854775808"));
+        Assert.assertTrue(result.contains("JSP - Long min value is 
-9223372036854775808"));
+    }
+}
diff --git a/test/webapp/bug6nnnn/bug66441.jsp 
b/test/webapp/bug6nnnn/bug66441.jsp
new file mode 100644
index 0000000000..ecc45c71bc
--- /dev/null
+++ b/test/webapp/bug6nnnn/bug66441.jsp
@@ -0,0 +1,23 @@
+<%--
+ 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="static java.lang.Long.MIN_VALUE"%>
+<html>
+  <body>
+    <p>EL  - Long min value is ${MIN_VALUE}</p>
+    <p>JSP - Long min value is <%= MIN_VALUE  %></p>
+  </body>
+</html>
\ No newline at end of file
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index dbb4473c4e..65e599d353 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -138,6 +138,10 @@
         <bug>66419</bug>: Fix calls from expression language to a method that
         accepts varargs when only one argument was passed. (markt)
       </fix>
+      <fix>
+        <bug>66441</bug>: Make imports of static fields in JSPs visible to any
+        EL expressions used on the page. (markt)
+      </fix>
     </changelog>
   </subsection>
 </section>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to