[ https://issues.apache.org/jira/browse/SLING-2712?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13561553#comment-13561553 ]
Bertrand Delacretaz commented on SLING-2712: -------------------------------------------- throw new IllegalArgumentException("Conversions to primitive types are not supported, cannot convert to " + whateverTypeWasAskedFor) is certainly more transparent than a vague NPE.... > Update JavaDocs of ValueMap wrt 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