Commons Configuration
  1. Commons Configuration
  2. CONFIGURATION-29

[configuration] SubsetConfiguration.getKeys() always appends "." delimiter to prefix

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

      Description

      When creating a SubsetConfiguration object, e.g.

      conf = new SubsetConfiguration(parentConf, "myprefixwithadot.");

      calls to conf.getProperty("prop") result in a call to
      parent.conf(conf.getPrefix() + "prop") as expected.

      However, a key iterator obtained by calling conf.getKeys() will only iterate
      over keys starting with (conf.getPrefix() + "."). In the example, this will be
      "myprefixwithadot..". There should not be a dot appended.

      The error is probably caused by line #283 in AbstractConfiguration.java

      return key.startsWith(prefix + ".") || key.equals(prefix);

        Activity

        Hide
        joerg.schaible@gmx.de added a comment -

        This is how it is supposed to work. Creating a subset always means a subset of a
        (valid) tree.

        Show
        joerg.schaible@gmx.de added a comment - This is how it is supposed to work. Creating a subset always means a subset of a (valid) tree.
        Hide
        Oliver Heger added a comment -

        Timo,

        what you have spotted may be a little inconsistency in the collaboration of
        SubsetConfiguration and its parent configuration, but I don't think it is critical.

        Why do you create your subset configuration by hand? You should rather use the
        subset() method of the Configuration interface for this purpose. This method
        correctly sets the delimiter. The key you pass into subset() should not end with
        a dot. Then everything should work as expected.

        Show
        Oliver Heger added a comment - Timo, what you have spotted may be a little inconsistency in the collaboration of SubsetConfiguration and its parent configuration, but I don't think it is critical. Why do you create your subset configuration by hand? You should rather use the subset() method of the Configuration interface for this purpose. This method correctly sets the delimiter. The key you pass into subset() should not end with a dot. Then everything should work as expected.
        Hide
        Emmanuel Bourg added a comment -

        On the other hand we might remove any trailing dot in the prefix.

        Why do you need a prefix ending with a dot ? Couldn't you simply use

        conf = new SubsetConfiguration(parentConf, "prefix");

        instead of

        conf = new SubsetConfiguration(parentConf, "prefix.");

        ?

        Show
        Emmanuel Bourg added a comment - On the other hand we might remove any trailing dot in the prefix. Why do you need a prefix ending with a dot ? Couldn't you simply use conf = new SubsetConfiguration(parentConf, "prefix"); instead of conf = new SubsetConfiguration(parentConf, "prefix."); ?
        Hide
        Timo Thomas added a comment -

        You are right. I can use subset("prefix") and it automatically appends a dot.
        Creating a subset that way getKeys() works as expected. I didn't see the
        subset() method at first and was misguided by the constructor

        SubsetConfiguration(Configuration parent, java.lang.String prefix,
        java.lang.String delimiter)

        which made me believe there is no default delimiter.

        Thanks for the fast reply.

        Show
        Timo Thomas added a comment - You are right. I can use subset("prefix") and it automatically appends a dot. Creating a subset that way getKeys() works as expected. I didn't see the subset() method at first and was misguided by the constructor SubsetConfiguration(Configuration parent, java.lang.String prefix, java.lang.String delimiter) which made me believe there is no default delimiter. Thanks for the fast reply.
        Hide
        Oliver Heger added a comment -

        I updated the documentation to point out that SubsetConfiguration should not be
        used directly and referred to the subset() method of Configuration. This is
        hopefully enough to avoid wrong usage of this class.

        Show
        Oliver Heger added a comment - I updated the documentation to point out that SubsetConfiguration should not be used directly and referred to the subset() method of Configuration. This is hopefully enough to avoid wrong usage of this class.

          People

          • Assignee:
            Unassigned
            Reporter:
            Timo Thomas
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development