Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Unable to use Java 8 Language features in JSP
I'm trying to use Java 8 streams within my init JSP, but running into errors. It seems that using lambdas or method references within a JSP breaks the JSP compiler. According to this LPS case, the issue was resolved on DXP fix pack 3,
I am currently on the latest fix pack (35) on my local development environment. I wasn't sure if there were any additional steps that I had to take to get this to work, or if this is in fact a regression bug.
Exception Generated (for both lambda and method reference):
I am currently on the latest fix pack (35) on my local development environment. I wasn't sure if there were any additional steps that I had to take to get this to work, or if this is in fact a regression bug.
//works (manual functional interface)
Arrays.stream(portletPreferences.getValues("selectedVocabularyIds", new String[]{}))
.map(new Function<string, long>() {
@Override
public Long apply(final String value) {
return Long.parseLong(value);
}
}).collect(Collectors.toList());
//doesn't work (lambda)
Arrays.stream(portletPreferences.getValues("selectedVocabularyIds", new String[]{}))
.map(id -> Long.parseLong(id))
.collect(Collectors.toList());
//doesn't work (method reference)
Arrays.stream(portletPreferences.getValues("selectedVocabularyIds", new String[]{}))
.map(Long::parseLong)
.collect(Collectors.toList());
</string,>
Exception Generated (for both lambda and method reference):
java.io.IOException: unexpected tag: 18
at org.apache.jasper.compiler.SmapUtil$SDEInstaller.copyConstantPool(SmapUtil.java:459)
at org.apache.jasper.compiler.SmapUtil$SDEInstaller.addSDE(SmapUtil.java:304)
at org.apache.jasper.compiler.SmapUtil$SDEInstaller.<init>(SmapUtil.java:257)
at org.apache.jasper.compiler.SmapUtil$SDEInstaller.install(SmapUtil.java:246)
at org.apache.jasper.compiler.SmapUtil.installSmap(SmapUtil.java:167)
at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:406)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:453)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:625)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
........
15:37:44,371 ERROR [http-apr-8080-exec-2][PortletRequestDispatcherImpl:265] Unable to dispatch request: PWC6033: Error in Javac compilation for JSP
</init>
As you're on DXP, you might want to open a support ticket. That's what it's there for. And the support staff loves you when you already come with an LPS reference, steps to reproduce, and are on the latest FP.
If your JSP is inside a module, it should work. If the JSP is inside a regular war you deploy to the application server, you also have to modify the entry web.xml for the JspServlet and set compilerSourceVM and compilerTargetVM (as documented in the Jasper How To) if you wish to use JDK 8 features in your JSPs, since it defaults to JDK 7.
@Olaf
This code was part of an existing front end web portlet, I am going to try to recreate on a vanilla portlet to confirm its an issue with the runtime and not a configuration error, before submitting a ticket
@Minhchau
This code is part of a OSGI module and not a WAR plugin
This code was part of an existing front end web portlet, I am going to try to recreate on a vanilla portlet to confirm its an issue with the runtime and not a configuration error, before submitting a ticket
@Minhchau
This code is part of a OSGI module and not a WAR plugin
I don't think it's a regression, since the code change that was submitted in LPS-66641 still exists (reference). It's more likely that it was never fixed and closed erroneously due to improper testing.
It's the same error as SMAP broken in Java 8 for JSP compile, so I'm guessing that we also needed to update a dependency in order to fix it.
It's the same error as SMAP broken in Java 8 for JSP compile, so I'm guessing that we also needed to update a dependency in order to fix it.
Minhchau Dang:
I don't think it's a regression, since the code change that was submitted in LPS-66641 still exists (reference). It's more likely that it was never fixed and closed erroneously due to improper testing.
It's the same error as SMAP broken in Java 8 for JSP compile, so I'm guessing that we also needed to update a dependency in order to fix it.
I think that would make the most sense. The code seems happy with Arrays.stream and Collectors.toList, so it is definitely compiling against Java 8, as Arrays.stream and the collector class did not exist in Java 7. My best guess is that its compiling against 1.8, but the parser in the dependency does not know how to handle the new lambda and method reference syntax.
Steps to reproduce:
- Deploy the attached bundle
- Add the Liferay Sample portlet to the page
Error in Javac compilation for JSPPWC6197: An error occurred at line: 4 in the jsp file: /view.jspApkjunky
PWC6199: Generated servlet error: lambda expressions are not supported in -source 1.7 (use -source 8 or higher to enable lambda expressions)
Seeing Jasper in stacktrace I expect you run LR on Tomcat. There is default source/target Java version value used for compiling JSP pages, which can be overridden in /conf/web.xml. Java 8 is default source/target since Tomcat 9 so I suppose you use Tomcat 8.x version. Here you have to add these lines to the proper section inside web.xml:
<init-param>
<param-name>compilerSourceVM</param-name>
<param-value>1.8</param-value>
</init-param>
<init-param>
<param-name>compilerTargetVM</param-name>
<param-value>1.8</param-value>
</init-param>
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™