[jira] Created: (CONFIGURATION-293) HierarchicalConfiguration.clearTree() does not remove named property

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] Created: (CONFIGURATION-293) HierarchicalConfiguration.clearTree() does not remove named property

David Costanzo (Jira)
HierarchicalConfiguration.clearTree() does not remove named property
--------------------------------------------------------------------

                 Key: CONFIGURATION-293
                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-293
             Project: Commons Configuration
          Issue Type: Bug
    Affects Versions: 1.4
            Reporter: Wesley Miaw


HierarchicalConfiguration.clearTree(String) calls HierarchicalConfiguration.removeNode(ConfigurationNode) which removes nothing if the passed in ConfigurationNode has no parent. Having no parent is true of nodes that have the root for their parent (it seems to me) as well as for nodes that have no properties defined "above" them. Here is an example:

config.addProperty("a.b.c", "c");
config.addProperty("a.b.c.d", "d");
config.addProperty("a.b.c.d.e", "e");

The following sequence of calls will fail:
config.clearTree("a.b.c");
assert config.containsKey("a.b.c") == false;

The following sequence of calls will succeed:
config.clearTree("a.b.c.d");
assert config.containsKey("a.b.c.d") == false;
assert config.containsKey("a.b.c.d.e") == false;

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (CONFIGURATION-293) HierarchicalConfiguration.clearTree() does not remove named property

David Costanzo (Jira)

    [ https://issues.apache.org/jira/browse/CONFIGURATION-293?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12521846 ]

Oliver Heger commented on CONFIGURATION-293:
--------------------------------------------

I tried to reproduce the problem, but without success. The following test case (which I have added to TestHierarchicalConfiguration) based on your description does not cause any problems (on the current SVN head):

    public void testClearTreeHierarchy()
    {
        config.addProperty("a.b.c", "c");
        config.addProperty("a.b.c.d", "d");
        config.addProperty("a.b.c.d.e", "e");
        config.clearTree("a.b.c");
        assertFalse("Property not removed", config.containsKey("a.b.c"));
        assertFalse("Sub property not removed", config.containsKey("a.b.c.d"));
    }

The code of removeNode() seems okay to me. It removes the affected node from its parent, which effectively causes the whole sub tree to be removed from the configuration.

Can you please double-check?

> HierarchicalConfiguration.clearTree() does not remove named property
> --------------------------------------------------------------------
>
>                 Key: CONFIGURATION-293
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-293
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Wesley Miaw
>
> HierarchicalConfiguration.clearTree(String) calls HierarchicalConfiguration.removeNode(ConfigurationNode) which removes nothing if the passed in ConfigurationNode has no parent. Having no parent is true of nodes that have the root for their parent (it seems to me) as well as for nodes that have no properties defined "above" them. Here is an example:
> config.addProperty("a.b.c", "c");
> config.addProperty("a.b.c.d", "d");
> config.addProperty("a.b.c.d.e", "e");
> The following sequence of calls will fail:
> config.clearTree("a.b.c");
> assert config.containsKey("a.b.c") == false;
> The following sequence of calls will succeed:
> config.clearTree("a.b.c.d");
> assert config.containsKey("a.b.c.d") == false;
> assert config.containsKey("a.b.c.d.e") == false;

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (CONFIGURATION-293) HierarchicalConfiguration.clearTree() does not remove named property

David Costanzo (Jira)
In reply to this post by David Costanzo (Jira)

    [ https://issues.apache.org/jira/browse/CONFIGURATION-293?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12521907 ]

Wesley Miaw commented on CONFIGURATION-293:
-------------------------------------------

Yeah. I looked into removeNode() and the code makes sense. I just tried again and it works, unless you have the following set up. I'll attach the bug-config.xml and the two files it tries to load up as well. (This is a CombinedConfiguration; I can only make this happen with the CombinedConfiguration, it works fine if either of the two files mentioned in bug-config.xml loses its inner-most definition (i.e. bug-override.xml only has <a></a> or bug-test.properties is empty).

        final String prefix = "a.b.c";
        public void clearTree() throws ConfigurationException {
                final URL xml = this.getClass().getClassLoader().getResource("bug-config.xml");
                final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(xml);
                final CombinedConfiguration config = (CombinedConfiguration)builder.getConfiguration(true);
               
                config.addProperty(prefix, "c");
                config.addProperty(prefix + ".d", "d");
                config.addProperty(prefix + ".d.e", "e");
       
                config.clearTree(prefix);
                assert !config.containsKey(prefix + ".d") : "Sub property not removed";
                assert !config.containsKey(prefix) : "Property not removed";
        }

> HierarchicalConfiguration.clearTree() does not remove named property
> --------------------------------------------------------------------
>
>                 Key: CONFIGURATION-293
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-293
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Wesley Miaw
>
> HierarchicalConfiguration.clearTree(String) calls HierarchicalConfiguration.removeNode(ConfigurationNode) which removes nothing if the passed in ConfigurationNode has no parent. Having no parent is true of nodes that have the root for their parent (it seems to me) as well as for nodes that have no properties defined "above" them. Here is an example:
> config.addProperty("a.b.c", "c");
> config.addProperty("a.b.c.d", "d");
> config.addProperty("a.b.c.d.e", "e");
> The following sequence of calls will fail:
> config.clearTree("a.b.c");
> assert config.containsKey("a.b.c") == false;
> The following sequence of calls will succeed:
> config.clearTree("a.b.c.d");
> assert config.containsKey("a.b.c.d") == false;
> assert config.containsKey("a.b.c.d.e") == false;

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Updated: (CONFIGURATION-293) HierarchicalConfiguration.clearTree() does not remove named property

David Costanzo (Jira)
In reply to this post by David Costanzo (Jira)

     [ https://issues.apache.org/jira/browse/CONFIGURATION-293?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Wesley Miaw updated CONFIGURATION-293:
--------------------------------------

    Attachment: bug-test.properties
                bug-override.xml
                bug-config.xml

The CombinedConfiguration initialization files for the situation described by this bug.

> HierarchicalConfiguration.clearTree() does not remove named property
> --------------------------------------------------------------------
>
>                 Key: CONFIGURATION-293
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-293
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Wesley Miaw
>         Attachments: bug-config.xml, bug-override.xml, bug-test.properties
>
>
> HierarchicalConfiguration.clearTree(String) calls HierarchicalConfiguration.removeNode(ConfigurationNode) which removes nothing if the passed in ConfigurationNode has no parent. Having no parent is true of nodes that have the root for their parent (it seems to me) as well as for nodes that have no properties defined "above" them. Here is an example:
> config.addProperty("a.b.c", "c");
> config.addProperty("a.b.c.d", "d");
> config.addProperty("a.b.c.d.e", "e");
> The following sequence of calls will fail:
> config.clearTree("a.b.c");
> assert config.containsKey("a.b.c") == false;
> The following sequence of calls will succeed:
> config.clearTree("a.b.c.d");
> assert config.containsKey("a.b.c.d") == false;
> assert config.containsKey("a.b.c.d.e") == false;

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (CONFIGURATION-293) HierarchicalConfiguration.clearTree() does not remove named property

David Costanzo (Jira)
In reply to this post by David Costanzo (Jira)

    [ https://issues.apache.org/jira/browse/CONFIGURATION-293?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12522059 ]

Oliver Heger commented on CONFIGURATION-293:
--------------------------------------------

Ah, I think I know now what is going on.

With a CombinedConfiguration things are a little bit different. The node structure of a combined configuration is constructed from the nodes of its contained child configurations each time one of the children is modified. In your test you remove a sub tree, which causes a child configuration to be changed and results in an update event. This event causes the combined configuration to be re-created. This time, because an override node combiner is used (the child configurations are defined in an <override> section), the just deleted sub tree is pulled in from another child configuration.

The following section of the user guide contains more information about updates on combined configurations; it should give you some background information about what is happening:
http://commons.apache.org/configuration/userguide/howto_combinedconfiguration.html#Dealing_with_changes

Well, how should this issue be treated? What you have found here is a known limitation of CombinedConfiguration. Given its design, it is not trivial to change. So I tend to resolve this issue as Won't fix. What do you think?

> HierarchicalConfiguration.clearTree() does not remove named property
> --------------------------------------------------------------------
>
>                 Key: CONFIGURATION-293
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-293
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Wesley Miaw
>         Attachments: bug-config.xml, bug-override.xml, bug-test.properties
>
>
> HierarchicalConfiguration.clearTree(String) calls HierarchicalConfiguration.removeNode(ConfigurationNode) which removes nothing if the passed in ConfigurationNode has no parent. Having no parent is true of nodes that have the root for their parent (it seems to me) as well as for nodes that have no properties defined "above" them. Here is an example:
> config.addProperty("a.b.c", "c");
> config.addProperty("a.b.c.d", "d");
> config.addProperty("a.b.c.d.e", "e");
> The following sequence of calls will fail:
> config.clearTree("a.b.c");
> assert config.containsKey("a.b.c") == false;
> The following sequence of calls will succeed:
> config.clearTree("a.b.c.d");
> assert config.containsKey("a.b.c.d") == false;
> assert config.containsKey("a.b.c.d.e") == false;

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (CONFIGURATION-293) HierarchicalConfiguration.clearTree() does not remove named property

David Costanzo (Jira)
In reply to this post by David Costanzo (Jira)

    [ https://issues.apache.org/jira/browse/CONFIGURATION-293?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12522195 ]

Wesley Miaw commented on CONFIGURATION-293:
-------------------------------------------

So I reimplemented clearTree() as follows, and it does what I expect it to do this way.

  Iterator<String> keys = getKeys(key);
  while (keys.hasNext()) {
    clearProperty(keys.next());
  }
  if (containsKey(key)) {
    clearProperty(key);
  }

the getKeys() while loop clears out all of the sub-properties, and clearProperty(key) does the right thing because it actually sets the value of the property to null. So even though the node isn't actually removed because it has no parent, it has no value anymore. From what I understand, this fulfills the contract of clear*(), since technically none of the clear*() methods say the nodes are removed, just that they have no value.

Of course, this fires off EVENT_CLEAR_PROPERTY instead of EVENT_CLEAR_TREE, but that's just because the above code calls the public methods.

But that doesn't really match up with how you described it (and as the documentation mentions). Why is it that in a non-CombinedConfiguration, the node would have a parent, but in a CombinedConfiguration, it doesn't?

> HierarchicalConfiguration.clearTree() does not remove named property
> --------------------------------------------------------------------
>
>                 Key: CONFIGURATION-293
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-293
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Wesley Miaw
>         Attachments: bug-config.xml, bug-override.xml, bug-test.properties
>
>
> HierarchicalConfiguration.clearTree(String) calls HierarchicalConfiguration.removeNode(ConfigurationNode) which removes nothing if the passed in ConfigurationNode has no parent. Having no parent is true of nodes that have the root for their parent (it seems to me) as well as for nodes that have no properties defined "above" them. Here is an example:
> config.addProperty("a.b.c", "c");
> config.addProperty("a.b.c.d", "d");
> config.addProperty("a.b.c.d.e", "e");
> The following sequence of calls will fail:
> config.clearTree("a.b.c");
> assert config.containsKey("a.b.c") == false;
> The following sequence of calls will succeed:
> config.clearTree("a.b.c.d");
> assert config.containsKey("a.b.c.d") == false;
> assert config.containsKey("a.b.c.d.e") == false;

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (CONFIGURATION-293) HierarchicalConfiguration.clearTree() does not remove named property

David Costanzo (Jira)
In reply to this post by David Costanzo (Jira)

    [ https://issues.apache.org/jira/browse/CONFIGURATION-293?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12522210 ]

Oliver Heger commented on CONFIGURATION-293:
--------------------------------------------

As far as I understand it, clearTree() indeed removes a node from the combined configuration. This affects the child configuration, from which this node was obtained. After that the combined configuration has to be re-constructed. In this process the used override combiner will again add a node that matches the just removed key - but this time it is obtained from the other child configuration.

The only save way of implementing your clearTree() method would be to iterate over all child configurations and to call clearTree() on them. Then you can be sure that all possible nodes have been removed.

> HierarchicalConfiguration.clearTree() does not remove named property
> --------------------------------------------------------------------
>
>                 Key: CONFIGURATION-293
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-293
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Wesley Miaw
>         Attachments: bug-config.xml, bug-override.xml, bug-test.properties
>
>
> HierarchicalConfiguration.clearTree(String) calls HierarchicalConfiguration.removeNode(ConfigurationNode) which removes nothing if the passed in ConfigurationNode has no parent. Having no parent is true of nodes that have the root for their parent (it seems to me) as well as for nodes that have no properties defined "above" them. Here is an example:
> config.addProperty("a.b.c", "c");
> config.addProperty("a.b.c.d", "d");
> config.addProperty("a.b.c.d.e", "e");
> The following sequence of calls will fail:
> config.clearTree("a.b.c");
> assert config.containsKey("a.b.c") == false;
> The following sequence of calls will succeed:
> config.clearTree("a.b.c.d");
> assert config.containsKey("a.b.c.d") == false;
> assert config.containsKey("a.b.c.d.e") == false;

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (CONFIGURATION-293) HierarchicalConfiguration.clearTree() does not remove named property

David Costanzo (Jira)
In reply to this post by David Costanzo (Jira)

    [ https://issues.apache.org/jira/browse/CONFIGURATION-293?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12522226 ]

Wesley Miaw commented on CONFIGURATION-293:
-------------------------------------------

I understand what you're saying, but tracing the code for clearTree() in this example case does not seem to modify the internal structure at all. So I don't see how the node is actually removed from anything.

Well, I'll let you guys figure out if you'd like to change this behavior, and if so, how you would do it. Iterating over the configurations to call clearTree() doesn't work because there's no guarantee a child configuration is an instance of HierarchicalConfiguration.

It just seems to me that CombinedConfiguration, as a subclass of HierarchicalConfiguration, should not result in behavior different than that documented by HierarchicalConfiguration, otherwise things don't do what you'd expect inheritance-wise.

> HierarchicalConfiguration.clearTree() does not remove named property
> --------------------------------------------------------------------
>
>                 Key: CONFIGURATION-293
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-293
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Wesley Miaw
>         Attachments: bug-config.xml, bug-override.xml, bug-test.properties
>
>
> HierarchicalConfiguration.clearTree(String) calls HierarchicalConfiguration.removeNode(ConfigurationNode) which removes nothing if the passed in ConfigurationNode has no parent. Having no parent is true of nodes that have the root for their parent (it seems to me) as well as for nodes that have no properties defined "above" them. Here is an example:
> config.addProperty("a.b.c", "c");
> config.addProperty("a.b.c.d", "d");
> config.addProperty("a.b.c.d.e", "e");
> The following sequence of calls will fail:
> config.clearTree("a.b.c");
> assert config.containsKey("a.b.c") == false;
> The following sequence of calls will succeed:
> config.clearTree("a.b.c.d");
> assert config.containsKey("a.b.c.d") == false;
> assert config.containsKey("a.b.c.d.e") == false;

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (CONFIGURATION-293) HierarchicalConfiguration.clearTree() does not remove named property

David Costanzo (Jira)
In reply to this post by David Costanzo (Jira)

    [ https://issues.apache.org/jira/browse/CONFIGURATION-293?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12522246 ]

Oliver Heger commented on CONFIGURATION-293:
--------------------------------------------

If nothing gets removed, this is probably because you have hit one of the "link" nodes that have been added by the NodeCombiner. Those nodes may indeed have no parent.

Your statements about inheritance do make sense. OTOH a CombinedConfiguration acts like a logic view on an arbitrary number of child configurations. And this view is constructed by a pluggable strategy, a NodeCombiner. In this scenario I simply see no way of implementing all the operations defined in HierarchicalConfiguration in a generic way that is compatible with each possible NodeCombiner. Hence the warning in the user guide about updates of a combined configuration. Maybe this fact should be made more obvious in the class's documentation?

> HierarchicalConfiguration.clearTree() does not remove named property
> --------------------------------------------------------------------
>
>                 Key: CONFIGURATION-293
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-293
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Wesley Miaw
>         Attachments: bug-config.xml, bug-override.xml, bug-test.properties
>
>
> HierarchicalConfiguration.clearTree(String) calls HierarchicalConfiguration.removeNode(ConfigurationNode) which removes nothing if the passed in ConfigurationNode has no parent. Having no parent is true of nodes that have the root for their parent (it seems to me) as well as for nodes that have no properties defined "above" them. Here is an example:
> config.addProperty("a.b.c", "c");
> config.addProperty("a.b.c.d", "d");
> config.addProperty("a.b.c.d.e", "e");
> The following sequence of calls will fail:
> config.clearTree("a.b.c");
> assert config.containsKey("a.b.c") == false;
> The following sequence of calls will succeed:
> config.clearTree("a.b.c.d");
> assert config.containsKey("a.b.c.d") == false;
> assert config.containsKey("a.b.c.d.e") == false;

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Commented: (CONFIGURATION-293) HierarchicalConfiguration.clearTree() does not remove named property

David Costanzo (Jira)
In reply to this post by David Costanzo (Jira)

    [ https://issues.apache.org/jira/browse/CONFIGURATION-293?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12522254 ]

Wesley Miaw commented on CONFIGURATION-293:
-------------------------------------------

Maybe examples would help to illustrate the issue. I took "It is not strictly forbidden to manipulate a CombinedConfiguration directly, but the results may be unpredictable." to mean if I tried to play around with its insides in a way other than the public interface.

> HierarchicalConfiguration.clearTree() does not remove named property
> --------------------------------------------------------------------
>
>                 Key: CONFIGURATION-293
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-293
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Wesley Miaw
>         Attachments: bug-config.xml, bug-override.xml, bug-test.properties
>
>
> HierarchicalConfiguration.clearTree(String) calls HierarchicalConfiguration.removeNode(ConfigurationNode) which removes nothing if the passed in ConfigurationNode has no parent. Having no parent is true of nodes that have the root for their parent (it seems to me) as well as for nodes that have no properties defined "above" them. Here is an example:
> config.addProperty("a.b.c", "c");
> config.addProperty("a.b.c.d", "d");
> config.addProperty("a.b.c.d.e", "e");
> The following sequence of calls will fail:
> config.clearTree("a.b.c");
> assert config.containsKey("a.b.c") == false;
> The following sequence of calls will succeed:
> config.clearTree("a.b.c.d");
> assert config.containsKey("a.b.c.d") == false;
> assert config.containsKey("a.b.c.d.e") == false;

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply | Threaded
Open this post in threaded view
|

[jira] Resolved: (CONFIGURATION-293) HierarchicalConfiguration.clearTree() does not remove named property

David Costanzo (Jira)
In reply to this post by David Costanzo (Jira)

     [ https://issues.apache.org/jira/browse/CONFIGURATION-293?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oliver Heger resolved CONFIGURATION-293.
----------------------------------------

       Resolution: Won't Fix
    Fix Version/s: 1.5

The javadocs for CombinedConfiguration have been updated with some examples why updates on such a configuration can be problematic.

Closing this issue as Won't fix because no code is altered.

> HierarchicalConfiguration.clearTree() does not remove named property
> --------------------------------------------------------------------
>
>                 Key: CONFIGURATION-293
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-293
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.4
>            Reporter: Wesley Miaw
>             Fix For: 1.5
>
>         Attachments: bug-config.xml, bug-override.xml, bug-test.properties
>
>
> HierarchicalConfiguration.clearTree(String) calls HierarchicalConfiguration.removeNode(ConfigurationNode) which removes nothing if the passed in ConfigurationNode has no parent. Having no parent is true of nodes that have the root for their parent (it seems to me) as well as for nodes that have no properties defined "above" them. Here is an example:
> config.addProperty("a.b.c", "c");
> config.addProperty("a.b.c.d", "d");
> config.addProperty("a.b.c.d.e", "e");
> The following sequence of calls will fail:
> config.clearTree("a.b.c");
> assert config.containsKey("a.b.c") == false;
> The following sequence of calls will succeed:
> config.clearTree("a.b.c.d");
> assert config.containsKey("a.b.c.d") == false;
> assert config.containsKey("a.b.c.d.e") == false;

--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.