Bug 66441 - Static field import failed on Expression Language lookup
Summary: Static field import failed on Expression Language lookup
Alias: None
Product: Tomcat 10
Classification: Unclassified
Component: Jasper (show other bugs)
Version: 10.1.5
Hardware: PC Mac OS X 10.1
: P2 normal (vote)
Target Milestone: ------
Assignee: Tomcat Developers Mailing List
Depends on:
Reported: 2023-01-24 18:12 UTC by Isaac Rivera Rivas
Modified: 2023-02-01 15:12 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Isaac Rivera Rivas 2023-01-24 18:12:47 UTC
Hello! Working with JSP pages and static imports using Tomcat's EL Jasper implementation, I found that importing a static field with EL lookup did not resolve to the correct value. Tried the following jsp

<%@ page import = "static myapp.Example.STATIC_VAR, static myapp.Example.STATIC_METHOD" %>
      <title>Import Static</title>
      EL expressions: <br/>

      JSP expressions: <br/>

The JSP expressions resolve as expected but of the EL expressions, only STATIC_METHOD() works. After some investigation we narrowed down that the problem may potentially be here https://github.com/apache/tomcat/blob/10.1.x/java/org/apache/el/parser/AstIdentifier.java#L101-L103 where the variable is resolved by the NotFoundELResolver and the import block to resolveStatic is not reached here https://github.com/apache/tomcat/blob/10.1.x/java/org/apache/el/parser/AstIdentifier.java#L105-L110. 

We are using the API from JakartaEE and not the API from Tomcat for Pages. If we change to Tomcat's API then it does behave as expected. This is because the ImportELResolver from Tomcat does a static lookup in its resolver here https://github.com/apache/tomcat/blob/10.1.x/java/jakarta/servlet/jsp/el/ImportELResolver.java#L85-L92 whereas the Jakarta API does not cover it here https://github.com/jakartaee/pages/blob/master/api/src/main/java/jakarta/servlet/jsp/el/ImportELResolver.java#L63-L71. Not sure if this should be fixed in the implementation of Tomcat or if it's something that should be address in the Jakarta Pages API. Any help is appreciated, thanks in advance!!
Comment 1 Isaac Rivera Rivas 2023-01-24 19:05:03 UTC
Here are a few clarifications for this issue,

1) This is for EE10 specifically, as we've tried to update our Open Liberty Pages Implementation to support static imports into the Expression Language environment. Before EE10, only JSP expressions could be used for this type of imports.

2) This scenario occurs with a mix up between Tomcat's EL API/Impl mixed with Jakarta Pages' 3.1 API.

3) Perhaps the Jakarta EE Pages API is more at fault and should be updated to look at static variables (via importHandler.resolveStatic), just as Tomcat ImportELResolver does. 

@Mark Thomas think you would know more here, any help would be appreciated! Thank you!
Comment 2 Mark Thomas 2023-01-25 14:54:53 UTC
This looks like a Jakarta EL API bug to me. I think it needs to handle the static field. It also looks like the EvaluationListener#propertyResolved() events aren't being triggered.
Comment 3 Mark Thomas 2023-02-01 14:35:15 UTC
Re-opening this as while Tomcat's pages API may handle this correctly, Jasper (Tomcat's pages implementation) does not.
Comment 4 Mark Thomas 2023-02-01 15:12:22 UTC
Fixed in:
- 11.0.x for 11.0.0-M3 onwards
- 10.1.x for 10.1.6 onwards
-  9.0.x for  9.0.72 onwards
-  8.5.x for  8.5.86 onwards