Uploaded image for project: 'Commons Configuration'
  1. Commons Configuration
  2. CONFIGURATION-441

CompositeConfiguration does not resolve referenced properties correctly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Invalid
    • 1.5
    • 1.7
    • Interpolation
    • None
    • all

    Description

      Imagine a composite configuration consisting of

      config_x : configuration one
      property.one=one
      property.two=two

      config_y : configuration two
      property.one.ref=${property.one}

      When getProperty() is called on a CompositeConfiguration, property interpolation does not work if a property in config_x refers to a property in config_y, in the example, property.one.ref won't translate into "one"

      This seems to be caused by the getProperty() implementation of CompositeConfiguration

      CompositeConfiguration.getProperty(String)
      /**
           * Read property from underlying composite
           *
           * @param key key to use for mapping
           *
           * @return object associated with the given configuration key.
           */
          public Object getProperty(String key)
          {
              Configuration firstMatchingConfiguration = null;
              for (Iterator i = configList.iterator(); i.hasNext();)
              {
                  Configuration config = (Configuration) i.next();
                  if (config.containsKey(key))
                  {
                      firstMatchingConfiguration = config;
                      break;
                  }
              }
      
              if (firstMatchingConfiguration != null)
              {
                  return firstMatchingConfiguration.getProperty(key);
              }
              else
              {
                  return null;
              }
          }
      

      The methods finds the first configuration containing the key, and delegates the call to that particular configuration.

      A possible fix would be to try interpolation against every configuration until an interpolation succeed.

      Attachments

        Activity

          People

            Unassigned Unassigned
            fabien_nisol Fabien Nisol
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: