[
https://issues.apache.org/jira/browse/SLING-2712?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13560753#comment-13560753
]
Felix Meschberger commented on SLING-2712:
------------------------------------------
Maybe supporting the primitive types may help, but ....
* The boxed type will always be returned which does *not* match the requested
type (unless the generics support also assumes autoboxing when deriving the
result type from the parameter type).
* More importantly: Requesting a primitive type and auto-unboxing the result
may result in a NullPointerException: The get method is specified to return
null if the the property does not exist. Auto-unboxing does no null-check (it
cannot because it does not know how to handle) and thus runs straight into the
NullPointerException.
I thus, in the interest of clarity and stability, suggest to not implement this
"feature" but instead enhance the JavaDoc to clearly state that primitive types
are not supported as type parameters and that instead the respective boxed type
should be used.
> ValueMap doesn't support primitive types
> ----------------------------------------
>
> Key: SLING-2712
> URL: https://issues.apache.org/jira/browse/SLING-2712
> Project: Sling
> Issue Type: Improvement
> Components: JCR
> Affects Versions: JCR Resource 2.2.4
> Reporter: Simone Tripodi
> Fix For: JCR Resource 2.2.4
>
>
> I have a {{Resource}} which has a property named {{releaseMonth}} which is of
> type {{long}}; then I have a simple {{NumberFormat}}
> {code}
> NumberFormat numberFormat = new DecimalFormat("00");
> {code}
> If I try to execute, in a JSP, the following code, to cast the
> {{releaseMonth}} property to the primitive {{long.class}}:
> {code}
> <%= numberFormat.format(properties.get("releaseMonth", long.class)) %>
> {code}
> It throws an exception:
> {code}
> Caused by: java.lang.IllegalArgumentException: Cannot format given
> Object as a Number
> at java.text.DecimalFormat.format(DecimalFormat.java:486)
> at java.text.Format.format(Format.java:140)
> at
> org.apache.jsp.apps.gtunes.album.html_jsp._jspService(html_jsp.java:171)
> at
> org.apache.sling.scripting.jsp.jasper.runtime.HttpJspBase.service(HttpJspB
> ase.java:70)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
> at
> org.apache.sling.scripting.jsp.jasper.servlet.JspServletWrapper.service(Js
> pServletWrapper.java:502)
> ... 68 more
> {code}
> If I use instead the primitive wrapper {{Long.class}}
> {code}
> <%= numberFormat.format(properties.get("releaseMonth", Long.class)) %>
> {code}
> everything works fine.
> Looks like that
> {code}
> properties.get("", long.class)
> {code}
> gets {{NULL}} back
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira