[
https://issues.apache.org/jira/browse/CONFIGURATION-373?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12683175#action_12683175
]
Oliver Heger commented on CONFIGURATION-373:
--------------------------------------------
My guess is that the problem is not related to {{HierarchicalConfiguration}},
but is caused by the way how you create the {{XMLConfiguration}} in your test
program. As the documentation of the {{append()}} method states, it does not
work well with hierarchical configurations:
{quote}
Note: This method won't work well when appending hierarchical configurations
because it is not able to copy information about the properties' structure
(i.e. the parent-child-relationships will get lost).
{quote}
Try using the constructor of {{XMLConfiguration}} that takes a
{{HierarchicalConfiguration}} as argument.
I would be very surprised if there was such a big bug in
{{HierarchicalConfiguration}}. One point is that our unit tests check adding
new branches using the syntax with the -1 index. Another point is that this is
a central feature of {{HierarchicalConfiguration}} that exists from the very
first release of this class. So if this did not work, certainly there would
have been lots of bug reports in the last years.
Can you please double-check? Thanks!
> HierarchicalConfiguration: adding a new branch using index (-1) does not work
> -----------------------------------------------------------------------------
>
> Key: CONFIGURATION-373
> URL: https://issues.apache.org/jira/browse/CONFIGURATION-373
> Project: Commons Configuration
> Issue Type: Bug
> Components: Expression engine
> Affects Versions: 1.6
> Environment: W2003, JDK 1.6
> Reporter: Antoine Morpain
>
> {code}
> addProperty("profiles.profile.name", "QAL");
> addProperty("profiles.profile(-1).name", "PROD"); // <- index (-1)
> to create a NEW branch
> // see:
> http://commons.apache.org/configuration/userguide/howto_xml.html#Hierarchical_properties
> - "Adding new properties"
> {code}
> should create a config like (XML view):
> {code:xml}
> <configuration>
> <profiles>
> <profile>
> <name>QAL</name>
> </profile>
> <profile>
> <name>PROD</name>
> </profile>
> </profiles>
> </configuration>
> {code}
> but it does this:
> {code:xml}
> <configuration>
> <profiles>
> <profile>
> <name>QAL</name>
> <- QAL and PROD
> <name>PROD</name>
> <- in the same branch !
> </profile>
> </profiles>
> </configuration>
> {code}
> Test program:
> {code}
> import org.apache.commons.configuration.ConfigurationException;
> import org.apache.commons.configuration.HierarchicalConfiguration;
> import org.apache.commons.configuration.XMLConfiguration;
> public class Main {
> public void doit(String[] args) throws
> ConfigurationException{
> HierarchicalConfiguration
> hc=new HierarchicalConfiguration();
>
> hc.addProperty("profiles.profile.name", "QAL");
>
> hc.addProperty("profiles.profile(-1).name", "PROD");
> XMLConfiguration x1=new
> XMLConfiguration();
> x1.append(hc);
> x1.save("conf.xml");
> System.exit(0);
> }
>
> public static void main(String[] args) throws ConfigurationException {
> Main main = new Main();
> main.doit(args);
> }
> }
> {code}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.