https://bz.apache.org/bugzilla/show_bug.cgi?id=69914

            Bug ID: 69914
           Summary: Java Record Getter Method Access in JSP EL Tomcat 10
                    to 11 Regression
           Product: Tomcat 11
           Version: 11.0.14
          Hardware: PC
            Status: NEW
          Severity: normal
          Priority: P2
         Component: EL
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: -------

In Tomcat 10.1.x (tested in 10.1.43) within a JSP we could access getter
methods on a record using just the property (.propertyName) notation in JSP EL.

Example:


public record Person(String firstName, String lastName) {
  public String getFullName() {
    return firstName + " " + lastName;
  }
}

Add a Person as a request attribute (model attribute in Spring MVC):

model.addAttribute("person", new Person("Robert", "Smith"));

Access "fullName" in the JSP:

${person.fullName}

This works in Tomcat 10.1, but in Tomcat 11 (11.0.15) throws the error:

Caused by: jakarta.servlet.ServletException: jakarta.servlet.jsp.JspException:
jakarta.el.PropertyNotFoundException: Property [fullName] not found on type
[app.controller.TestController$Person]
        at
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:600)
        at
org.apache.jsp.WEB_002dINF.views.test_jsp._jspService(test_jsp.java:177)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:64)
        at jakarta.servlet.http.HttpServlet.service(HttpServlet.java:710)
        at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:428)
        ... 180 more
Caused by: jakarta.el.PropertyNotFoundException: Property [fullName] not found
on type [app.controller.TestController$Person]
        at jakarta.el.RecordELResolver.getValue(RecordELResolver.java:72)
        at
org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:128)
        at org.apache.el.parser.AstValue.getValue(AstValue.java:154)
        at
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:150)
        at
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:636)
        at
org.apache.jsp.WEB_002dINF.views.test_jsp$Helper.invoke0(about_jsp.java:1015)
        at
org.apache.jsp.WEB_002dINF.views.test_jsp$Helper.invoke(about_jsp.java:1037)
        at org.apache.jsp.tag.web.page_tag.doTag(page_tag.java:346)
        at
org.apache.jsp.WEB_002dINF.views.about_jsp._jspx_meth_t_005fpage_005f0(test_jsp.java:197)
        at
org.apache.jsp.WEB_002dINF.views.about_jsp._jspService(test_jsp.java:164)
        ... 183 more
Caused by: java.lang.NoSuchMethodException:
app.controller.TestController$Person.fullName()
        at java.base/java.lang.Class.getMethod(Class.java:2395)
        at jakarta.el.RecordELResolver.getValue(RecordELResolver.java:69)


Using the full method name in JSP EL works in both versions of Tomcat:

${person.getFullName()}

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to