[jira] [Updated] (SLING-6458) Java 8 features (lambdas, method references, etc) are not supported

2017-01-13 Thread Henry Kuijpers (JIRA)

 [ 
https://issues.apache.org/jira/browse/SLING-6458?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Henry Kuijpers updated SLING-6458:
--
Description: 
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=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 

[jira] [Updated] (SLING-6458) Java 8 features (lambdas, method references, etc) are not supported

2017-01-13 Thread Henry Kuijpers (JIRA)

 [ 
https://issues.apache.org/jira/browse/SLING-6458?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Henry Kuijpers updated SLING-6458:
--
Description: 
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=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/products/somos/en_US/account/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/products/somos/en_US/account/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