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

Felix Meschberger commented on SLING-2712:
------------------------------------------

Yes, throwing violates the contract. In fact null is not only returned if the 
property does not exist, it is also returned if the property cannot be 
converted to the requested type. So the second case applies here (impossible 
conversion) and null must be returned.

Hmm, maybe we should also clarify this one: null is returned if conversion to 
the requested type is not possible.
                
> 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: API 2.3.0
>            Reporter: Simone Tripodi
>            Assignee: Carsten Ziegeler
>             Fix For: API 2.3.2
>
>
> 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

Reply via email to