JSP optimize-scriplets causes compilation failure when string concatenation exists inside method arguments in expression on EAP 6.x/7.x

Solution Unverified - Updated -

Issue

In EAP 7, when optimize-scriplets="true" is enabled in undertow subsystem and a JSP has the following expression which string concatenation exists inside method arguments:

<img src='<%=response.encodeURL(request.getContextPath() + "/image/test.jpg")%>'/>

The JSP request fails due to compile error with the following log message:

ERROR [io.undertow.request] (default task-1) UT005023: Exception handling request to /test/example.jsp: org.apache.jasper.JasperException: JBWEB004062: Unable to compile class for JSP: 

JBWEB004060: An error occurred at line: 1 in the jsp file: /example.jsp
The method print(String) in the type JspWriter is not applicable for the arguments (String, void)
1: <img src='<%=response.encodeURL(request.getContextPath() + "/image/test.jpg")%>'/>


JBWEB004060: An error occurred at line: 1 in the jsp file: /example.jsp
Syntax error on token ";", , expected
1: <img src='<%=response.encodeURL(request.getContextPath() + "/image/test.jpg")%>'/>


Stacktrace:
    at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:95)
    at org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:198)
    at org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:455)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:359)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
    at org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
    at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:652)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:358)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:403)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:347)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    ...

The same issue also happens on EAP 6 when -Dorg.apache.jasper.compiler.Parser.OPTIMIZE_SCRIPTLETS=true is enabled.

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x
    • 7.x

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content