[ 
https://issues.apache.org/jira/browse/SLING-6458?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15821681#comment-15821681
 ] 

Carsten Ziegeler commented on SLING-6458:
-----------------------------------------

The compiler we use supports Java 8 and our configuration for source/target 
definitely supports Java 8. I know that if you run Sling on Java 8 it will 
generate 1.8 byte code and run fine with it. So I think it's rather the Jasper 
version, the Eclipse compiler we use should be able to handle these things

For reference we use this version of the compiler:
            <groupId>org.eclipse.jdt.core.compiler</groupId>
            <artifactId>ecj</artifactId>
            <version>4.5.1</version>


> JSP scripting does not support Java 8 features (lambdas, method references, 
> etc)
> --------------------------------------------------------------------------------
>
>                 Key: SLING-6458
>                 URL: https://issues.apache.org/jira/browse/SLING-6458
>             Project: Sling
>          Issue Type: Bug
>          Components: Scripting
>    Affects Versions: Scripting JSP 2.0.28, Scripting JSP 2.1.0, Scripting JSP 
> 2.1.4, Scripting JSP 2.1.6, Scripting JSP 2.1.8, Scripting JSP 2.2.0, 
> Scripting JSP 2.2.2, Scripting JSP 2.2.4, Scripting JSP 2.2.6
>            Reporter: Henry Kuijpers
>
> When trying to use Java 8 functionality in a JSP file, the Jasper framework 
> in the Sling Scripting bundle fails to compile the JSP file. It seems to get 
> stuck on a Java 8 feature: Lambdas.
> {code}
> <%@page session="false" %>
> <%@ page import="java.util.stream.IntStream" %>
> <%@ page import="java.io.IOException" %>
> <%
>     out.println("Lambda test");
>     IntStream leip = IntStream.of(1, 2, 3, 4, 5, 6);
>     final JspWriter out2 = out;
>     leip.forEach(x -> {
>         try {
>             out2.println(x);
>         } catch (IOException e) {
>             // Intentionally do nothing
>         }
>     });
> %>
> {code}
> When we remove the complete "leip.forEach" statement, the code compiles and 
> executes successfully.
> Upon further investigation, I found out that the Jasper compiler that is 
> being used, does not have support for "tag 18", which seems to be the lambda 
> feature in Java 8.
> I could find the constant pool tags over here: 
> https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4-140 
> Clearly, there is no support for MethodHandle, MethodType, InvokeDynamic.
> I could find a bug report for Tomcat (where Jasper is developed) over here: 
> https://bz.apache.org/bugzilla/show_bug.cgi?id=54475 
> It seems that the issue was fixed in a newer version of Jasper, namely 
> 6.0.40. We are currently using 6.0.14 (which is in Apache Sling Scripting JSP 
> version bundle version 2.1.4). 
> I tried looking at 
> https://mvnrepository.com/artifact/org.apache.sling/org.apache.sling.scripting.jsp
>  but for some reason all newer versions are also embedding Jasper 6.0.14 
> (which does not support Java 8) and in the custom code inside that bundle I 
> also do not see any cases for 18 in the switch statement in 
> SmapUtil$SDEInstaller.copyConstantPool. Nor do I see any traces that look 
> like this fix: 
> https://bz.apache.org/bugzilla/attachment.cgi?id=31416&action=diff
> See below a stacktrace of what's happening:
> {code}
> 12.01.2017 14:39:19.063 *ERROR* [144.119.190.210 [1484228359038] POST 
> /content/page/sign-up.html HTTP/1.1] 
> org.apache.sling.servlets.get.impl.DefaultGetServlet No renderer for 
> extension html, cannot render resource ResourceWrapper, 
> type=test/components/form/actions/register, 
> path=/content/page/sign-up/jcr:content/par/start, resource=[JcrNodeResource, 
> type=foundation/components/form/start, superType=null, 
> path=/content/page/sign-up/jcr:content/par/start]
> 12.01.2017 14:39:19.079 *ERROR* [144.119.190.210 [1484228359038] POST 
> /content/page/sign-up.html HTTP/1.1] com.day.cq.wcm.tags.IncludeTag Error 
> while executing script 
> /apps/test/components/form/actions/register/post.POST.jsp 
> org.apache.sling.api.scripting.ScriptEvaluationException: 
> org.apache.sling.scripting.jsp.jasper.JasperException: Unable to compile 
> class for JSP
>         at 
> org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:388)
>         at 
> org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:171)
>         at 
> org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:463)
>         at com.day.cq.wcm.tags.IncludeTag.includeScript(IncludeTag.java:167)
>         at com.day.cq.wcm.tags.IncludeTag.doEndTag(IncludeTag.java:87)
>         at 
> org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
>         at 
> org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:502)
>         at 
> org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:449)
>         at 
> org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:281)
>         at 
> org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:102)
>         at 
> org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:524)
>         at 
> org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:361)
>         at 
> org.apache.sling.scripting.core.impl.DefaultSlingScript.eval(DefaultSlingScript.java:171)
>         at 
> org.apache.sling.scripting.core.impl.DefaultSlingScript.service(DefaultSlingScript.java:463)
>         at 
> org.apache.sling.engine.impl.request.RequestData.service(RequestData.java:508)
>         at 
> org.apache.sling.engine.impl.filter.SlingComponentFilterChain.render(SlingComponentFilterChain.java:45)
>               ... filters ommitted for brevity ...
>         at 
> com.day.j2ee.servletengine.RequestDispatcherImpl.doFilter(RequestDispatcherImpl.java:321)
>         at 
> com.day.j2ee.servletengine.RequestDispatcherImpl.service(RequestDispatcherImpl.java:340)
>         at 
> com.day.j2ee.servletengine.RequestDispatcherImpl.service(RequestDispatcherImpl.java:383)
>         at 
> com.day.j2ee.servletengine.ServletHandlerImpl.process(ServletHandlerImpl.java:335)
>         at 
> com.day.j2ee.servletengine.HttpListener$Worker.run(HttpListener.java:644)
>         at java.lang.Thread.run(Thread.java:745)
> Caused by: org.apache.sling.api.SlingException: 
> org.apache.sling.scripting.jsp.jasper.JasperException: Unable to compile 
> class for JSP
>         at 
> org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspExceptionInternal(JspServletWrapper.java:691)
>         at 
> org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:608)
>         at 
> org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:525)
>         at 
> org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:449)
>         at 
> org.apache.sling.scripting.jsp.JspScriptEngineFactory.callJsp(JspScriptEngineFactory.java:281)
>         at 
> org.apache.sling.scripting.jsp.JspScriptEngineFactory.access$100(JspScriptEngineFactory.java:102)
>         at 
> org.apache.sling.scripting.jsp.JspScriptEngineFactory$JspScriptEngine.eval(JspScriptEngineFactory.java:524)
>         at 
> org.apache.sling.scripting.core.impl.DefaultSlingScript.call(DefaultSlingScript.java:361)
>         ... 121 more
> Caused by: java.io.IOException: unexpected tag: 18
>         at 
> org.apache.sling.scripting.jsp.jasper.compiler.SmapUtil$SDEInstaller.copyConstantPool(SmapUtil.java:491)
>         at 
> org.apache.sling.scripting.jsp.jasper.compiler.SmapUtil$SDEInstaller.addSDE(SmapUtil.java:308)
>         at 
> org.apache.sling.scripting.jsp.jasper.compiler.SmapUtil$SDEInstaller.<init>(SmapUtil.java:264)
>         at 
> org.apache.sling.scripting.jsp.jasper.compiler.SmapUtil$SDEInstaller.install(SmapUtil.java:243)
>         at 
> org.apache.sling.scripting.jsp.jasper.compiler.SmapUtil.installSmap(SmapUtil.java:167)
>         at 
> org.apache.sling.scripting.jsp.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:151)
>         at 
> org.apache.sling.scripting.jsp.jasper.compiler.Compiler.compile(Compiler.java:312)
>         at 
> org.apache.sling.scripting.jsp.jasper.compiler.Compiler.compile(Compiler.java:290)
>         at 
> org.apache.sling.scripting.jsp.jasper.compiler.Compiler.compile(Compiler.java:277)
>         at 
> org.apache.sling.scripting.jsp.jasper.JspCompilationContext.compile(JspCompilationContext.java:501)
>         at 
> org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.prepareServlet(JspServletWrapper.java:427)
>         at 
> org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:486)
>         ... 126 more
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to