Uploaded image for project: 'Felix'
  1. Felix
  2. FELIX-5399

Unable to define default map or list config types

    XMLWordPrintableJSON

Details

    Description

      Assume you have a key in a given configuration dictionary which corresponds to a map or a list.
      For example:

      map={key1=value1, key2=value2}
      list=[a,b,c}
      

      Now assume we have the corresponding configuration type, which defines default values for the "map" or "list" keys:

          public interface ConfigType {
              public default List<String> getList() { 
              	return Arrays.asList("default1", "default2");
              }
      
              public default SortedMap<String, String> getMap() { 
              	SortedMap<String, String> defaultMap = new TreeMap<>();
              	defaultMap.put("key1", "default1");
              	defaultMap.put("key2", "default2");
              	return defaultMap;
              }        
          }
      

      Now, assume also that:

      • you use an optional configurationdependency and the configuration is currently unavailable
      • or the configuration is currently available (whatever the configuration dependency is optional or required), but there is currently no values for "map" or "list" keys

      Then the problem is that the default map or list values declared in the ConfigType interface are not used as default values, but instead when you access to the "map" or "list" configuration keys, then you get an implicit empty map or an empty list (instead of the defaults values defined in the configuration type)

      See org.apache.felix.dm.itest.api.DefaultListConfigType.java and org.apache.felix.dm.itest.api.DefaultMapConfigType, which reproduce the issue.

      Attachments

        Activity

          People

            pderop Pierre De Rop
            pderop Pierre De Rop
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: