You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Andreas Vogl (JIRA)" <ji...@apache.org> on 2008/08/05 12:02:44 UTC

[jira] Created: (SLING-600) ValueMap#get(String s, T obj) does not work with java.util.Calendar

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.


[jira] Assigned: (SLING-600) ValueMap#get(String s, T obj) does not work with java.util.Calendar

Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SLING-600?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Felix Meschberger reassigned SLING-600:
---------------------------------------

    Assignee: Felix Meschberger

> 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
>            Assignee: Felix Meschberger
>
> 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.


[jira] Resolved: (SLING-600) ValueMap#get(String s, T obj) does not work with java.util.Calendar

Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/SLING-600?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Felix Meschberger resolved SLING-600.
-------------------------------------

       Resolution: Fixed
    Fix Version/s: JCR Resource 2.0.4

Fixed in Rev. 682984 as indicated above. Also deployed SNAPSHOT version 2.0.3-incubator-20080805.215826-3.

Please close the issue if the fix works for you. Thanks.

> 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
>            Assignee: Felix Meschberger
>             Fix For: JCR Resource 2.0.4
>
>
> 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.


[jira] Commented: (SLING-600) ValueMap#get(String s, T obj) does not work with java.util.Calendar

Posted by "Felix Meschberger (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/SLING-600?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12620063#action_12620063 ] 

Felix Meschberger commented on SLING-600:
-----------------------------------------

The problem is that the JcrPropertyMap.get(String, T) method uses the runtime type of the object to select the type for the conversion in the convertToType method. This results in the convertToType method in your example to be called with the GregorianCalendar class which does not equal any of the checked classes.

The fix is to special case some types supported by the convertToType method: Calendar and Value. Both are interfaces of which the default value may be an implementation.

> 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
>            Assignee: Felix Meschberger
>
> 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.