JSP optimize-scriplets causes compilation failure when string concatenation exists inside method arguments in expression on EAP 6.x/7.x
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 6.x
- 7.x
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.
Resolution
- This issue is reported as the following JIRAs, which will be fixed in the future releases (EAP 7.1.6 and 7.2.1 tentatively):
- Until the above JIRA is fixed, avoid using the option
optimize-scriplets="true"in EAP 7 and the system property-Dorg.apache.jasper.compiler.Parser.OPTIMIZE_SCRIPTLETS=truein EAP 6 when you have such expression in JSP.
SBR
Components
Category
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.