ValueMap#get(String s, T obj) does not work with java.util.Calendar
-------------------------------------------------------------------
Key: SLING-600
URL: https://issues.apache.org/jira/browse/SLING-600
Project: Sling
Issue Type: Bug
Components: JCR Resource
Environment: Windows XP, Sling Version 2.0.3-incubator-SNAPSHOT
(running on Communiqué5)
Reporter: Andreas Vogl
I am using the sling api (Version 2.0.3-incubator-SNAPSHOT) to access
properties from a JCR repository and have noticed something strange in the class
org.apache.sling.api.resource.ValueMap
The method "<T> T get(java.lang.String name, T defaultValue)" allows to pass a
default value. It will return the default value if the property "name" does not
exist in the map. This works fine for many types such as String, Long and
Boolean - but apparently it does not work for Calendar properties.
The problem is that when i pass a default value of type java.util.Calendar, the
get method always returns the default value regardless wether there is a
property "name" or not. Wether the property "name" is of type "Date" (in the
JCR repository) or of type "String" does not seem to make a difference.
The following example code can be used to reproduce the problem:
ValueMap map = resource.adaptTo(ValueMap.class);
// this does not work
Calendar defaultCalendar = new GregorianCalendar();
Calendar dateValue = map.get("dateProperty", defaultCalendar); // <- always
returns defaultCalendar
log.debug("dateProperty with default = "+(dateValue == null ? "null" :
dateValue.get(Calendar.MONTH)+"."+dateValue.get(Calendar.YEAR)));
// without default value - works fine
dateValue = map.get("dateProperty", Calendar.class); // <- correctly returns
the dateProperty value
log.debug("dateProperty no default = "+(dateValue == null ? "null" :
dateValue.get(Calendar.MONTH)+"."+dateValue.get(Calendar.YEAR)));
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.