Uploaded image for project: 'Sling'
  1. Sling
  2. SLING-600

ValueMap#get(String s, T obj) does not work with java.util.Calendar

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • JCR Resource 2.0.4
    • JCR
    • None
    • Windows XP, Sling Version 2.0.3-incubator-SNAPSHOT (running on Communiqué5)

    Description

      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)));

      Attachments

        Activity

          People

            fmeschbe Felix Meschberger
            vogla Andreas Vogl
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: