[jira] Created: (CONFIGURATION-328) XMLConfiguration addNodes() not behaving correctly (in 1.5)

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

[jira] Created: (CONFIGURATION-328) XMLConfiguration addNodes() not behaving correctly (in 1.5)

JIRA jira@apache.org
XMLConfiguration addNodes() not behaving correctly (in 1.5)
-----------------------------------------------------------

                 Key: CONFIGURATION-328
                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-328
             Project: Commons Configuration
          Issue Type: Bug
    Affects Versions: 1.5
         Environment: Linux, Apache Configuration 1.5
            Reporter: vivek
            Priority: Blocker


Things used to work fine in 1.3, but now when I'm trying 1.5 my JUnit test suite is breaking when adding new properties. Here is what I'm doing,

1) I already have a configuration as following,

 <test>
                          <property name="isOk">
                                  <value>true</value>
                                  <default>false</default>
                          </property>
                           <property name="intProperty">
                                  <value>900</value>
                                  <default>500</default>
   </property>
                          <property extra="0" name="stringProperty">
                                  <value>Hi</value>
                                  <default>Bye</default>
                          </property>
     </test>

2) Now I need to add two new properties under <test>,

<property  name="newFirst">
      <value>first</value>
</property>
<property name="newSecond">
       <value>second</value>
</property>

3) Here is the code I'm using,

        a) First create a new HierarchicalConfiguration.Node
                 private HierarchicalConfiguration.Node createNode(String name, Object value)  {
                        HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node(name);
                        node.setValue(value);
                        return node;
                  }
                 
       b) Add the node to the list
          List<HierarchicalConfiguration.Node> attrNodes = new ArrayList<HierarchicalConfiguration.Node>();
                Node attrNode = createNode(attrName, newPropertyName);
                attrNode.setAttribute(true);
                attrNodes.add(attrNode);
       
       c) Call addNodes on XMLConfiguration,
                  conf.addNodes(attrPath, attrNodes);

I run this in a look for each new property I need to add. For first property, I get element count for the test.property as 3 (conf.getMaxIndex(key)) - so I insert at test.property(3), which is right, but for the second property I get element count as 5 --> This is wrong, it should have been 4 (because I just added 1).

I check the saved the configuration file after adding those two new properties and it looks wrong too. Here is what I get,

                 <test>
                          <property name="isOk">
                                  <value>true</value>
                                  <default>false</default>
                          </property>
                           <property name="intProperty">
                                  <value>900</value>
                                  <default>500</default>
                          </property>
                          <property extra="0" name="stringProperty">
                                  <value>Hi</value>
                                  <default>Bye</default>
                          </property>
                        <property>
                             <name>newFirst</name>
                        </property>
                        <property>
                             <value>first</value>
                         </property>
                         <property>
                             <name>newSecond</name>
                        </property>
                        <property>
                             <value>second</value>
                         </property>
                 </test>


The total element count for test.property gives me 7 ==> I was expecting 5.


There seems to have some code change in 1.5 releated to addNodes (for ex., CONFIGURATION-287). I'm not sure if I need to change the way I was calling addNodes before. It works fine with 1.3, but 1.5 completely fails on adding new properties.

I do need 1.5 for other bug fixes ( CONFIGURATION-268 and some other), but I can't use it until the addNodes behave correctly.

Marking this as blocker as I'm blocked because of this issue. If there is a workaround then please let me know.

--
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-328) XMLConfiguration addNodes() not behaving correctly (in 1.5)

JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/CONFIGURATION-328?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12597767#action_12597767 ]

vivek commented on CONFIGURATION-328:
-------------------------------------

Looks like the attribute is getting added as new tag,

<property>
<name>newFirst</name>
</property>
<property>
<value>first</value>
</property>

is supposed to be,

 <property name="newFirst">
     <value>first</value>
 </property>

In my code,

1) I first add the <property> tag under the <test> element - by calling conf.addNodes
2) Then I add the name attribute to the newly added property - again by calling conf.addNodes
3) Then I add the value tag under property - again by calling conf.addNodes

I do create a new HierarchicalConfiguration.Node every time to add it.  

It all used to work fine in 1.3, but it's failing in 1.5.

Note, my reloading strategy is false - not sure if that has anything to do with this.

> XMLConfiguration addNodes() not behaving correctly (in 1.5)
> -----------------------------------------------------------
>
>                 Key: CONFIGURATION-328
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-328
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.5
>         Environment: Linux, Apache Configuration 1.5
>            Reporter: vivek
>            Priority: Blocker
>
> Things used to work fine in 1.3, but now when I'm trying 1.5 my JUnit test suite is breaking when adding new properties. Here is what I'm doing,
> 1) I already have a configuration as following,
>  <test>
>  <property name="isOk">
>  <value>true</value>
>  <default>false</default>
>  </property>
>   <property name="intProperty">
>  <value>900</value>
>  <default>500</default>
>    </property>
>  <property extra="0" name="stringProperty">
>  <value>Hi</value>
>  <default>Bye</default>
>  </property>
>      </test>
> 2) Now I need to add two new properties under <test>,
> <property  name="newFirst">
>       <value>first</value>
> </property>
> <property name="newSecond">
>        <value>second</value>
> </property>
> 3) Here is the code I'm using,
>         a) First create a new HierarchicalConfiguration.Node
>                  private HierarchicalConfiguration.Node createNode(String name, Object value)  {
>                         HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node(name);
>                         node.setValue(value);
>                         return node;
>                   }
>                  
>        b) Add the node to the list
>           List<HierarchicalConfiguration.Node> attrNodes = new ArrayList<HierarchicalConfiguration.Node>();
> Node attrNode = createNode(attrName, newPropertyName);
> attrNode.setAttribute(true);
> attrNodes.add(attrNode);
>        
>        c) Call addNodes on XMLConfiguration,
>                   conf.addNodes(attrPath, attrNodes);
> I run this in a look for each new property I need to add. For first property, I get element count for the test.property as 3 (conf.getMaxIndex(key)) - so I insert at test.property(3), which is right, but for the second property I get element count as 5 --> This is wrong, it should have been 4 (because I just added 1).
> I check the saved the configuration file after adding those two new properties and it looks wrong too. Here is what I get,
>                  <test>
>  <property name="isOk">
>  <value>true</value>
>  <default>false</default>
>  </property>
>   <property name="intProperty">
>  <value>900</value>
>  <default>500</default>
>  </property>
>  <property extra="0" name="stringProperty">
>  <value>Hi</value>
>  <default>Bye</default>
>  </property>
>        <property>
>                              <name>newFirst</name>
>                         </property>
>                         <property>
>                              <value>first</value>
>                          </property>
>                          <property>
>                              <name>newSecond</name>
>                         </property>
>                         <property>
>                              <value>second</value>
>                          </property>
>                  </test>
> The total element count for test.property gives me 7 ==> I was expecting 5.
> There seems to have some code change in 1.5 releated to addNodes (for ex., CONFIGURATION-287). I'm not sure if I need to change the way I was calling addNodes before. It works fine with 1.3, but 1.5 completely fails on adding new properties.
> I do need 1.5 for other bug fixes ( CONFIGURATION-268 and some other), but I can't use it until the addNodes behave correctly.
> Marking this as blocker as I'm blocked because of this issue. If there is a workaround then please let me know.

--
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-328) XMLConfiguration addNodes() not behaving correctly

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

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

Emmanuel Bourg updated CONFIGURATION-328:
-----------------------------------------

      Description:
Things used to work fine in 1.3, but now when I'm trying 1.5 my JUnit test suite is breaking when adding new properties. Here is what I'm doing,

1) I already have a configuration as following,

{code:xml}
 <test>
  <property name="isOk">
    <value>true</value>
    <default>false</default>
  </property>
  <property name="intProperty">
    <value>900</value>
    <default>500</default>
  </property>
  <property extra="0" name="stringProperty">
    <default>Bye</default>
  </property>
</test>
{code}

2) Now I need to add two new properties under <test>,

{code:xml}
<property  name="newFirst">
  <value>first</value>
</property>
<property name="newSecond">
  <value>second</value>
</property>
{code}

3) Here is the code I'm using,

        a) First create a new HierarchicalConfiguration.Node
{code:java}
private HierarchicalConfiguration.Node createNode(String name, Object value)  {
    HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node(name);
    node.setValue(value);
    return node;
}
{code}
                 
       b) Add the node to the list
{code:java}
List<HierarchicalConfiguration.Node> attrNodes = new ArrayList<HierarchicalConfiguration.Node>();
Node attrNode = createNode(attrName, newPropertyName);
attrNode.setAttribute(true);
attrNodes.add(attrNode);
{code}
       
       c) Call addNodes on XMLConfiguration,
{code:java}
    conf.addNodes(attrPath, attrNodes);
{code}

I run this in a look for each new property I need to add. For first property, I get element count for the test.property as 3 (conf.getMaxIndex(key)) - so I insert at test.property(3), which is right, but for the second property I get element count as 5 --> This is wrong, it should have been 4 (because I just added 1).

I check the saved the configuration file after adding those two new properties and it looks wrong too. Here is what I get,
{code:xml}
<test>
  <property name="isOk">
    <value>true</value>
    <default>false</default>
  </property>
  <property name="intProperty">
    <value>900</value>
    <default>500</default>
  </property>
  <property extra="0" name="stringProperty">
    <value>Hi</value>
    default>Bye</default>
  </property>
  <property>
    <name>newFirst</name>
  </property>
  <property>
    <value>first</value>
  </property>
  <property>
    <name>newSecond</name>
  </property>
  <property>
    <value>second</value>
  </property>
</test>
{code}

The total element count for test.property gives me 7 ==> I was expecting 5.


There seems to have some code change in 1.5 releated to addNodes (for ex., CONFIGURATION-287). I'm not sure if I need to change the way I was calling addNodes before. It works fine with 1.3, but 1.5 completely fails on adding new properties.

I do need 1.5 for other bug fixes ( CONFIGURATION-268 and some other), but I can't use it until the addNodes behave correctly.

Marking this as blocker as I'm blocked because of this issue. If there is a workaround then please let me know.

  was:
Things used to work fine in 1.3, but now when I'm trying 1.5 my JUnit test suite is breaking when adding new properties. Here is what I'm doing,

1) I already have a configuration as following,

 <test>
                          <property name="isOk">
                                  <value>true</value>
                                  <default>false</default>
                          </property>
                           <property name="intProperty">
                                  <value>900</value>
                                  <default>500</default>
   </property>
                          <property extra="0" name="stringProperty">
                                  <value>Hi</value>
                                  <default>Bye</default>
                          </property>
     </test>

2) Now I need to add two new properties under <test>,

<property  name="newFirst">
      <value>first</value>
</property>
<property name="newSecond">
       <value>second</value>
</property>

3) Here is the code I'm using,

        a) First create a new HierarchicalConfiguration.Node
                 private HierarchicalConfiguration.Node createNode(String name, Object value)  {
                        HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node(name);
                        node.setValue(value);
                        return node;
                  }
                 
       b) Add the node to the list
          List<HierarchicalConfiguration.Node> attrNodes = new ArrayList<HierarchicalConfiguration.Node>();
                Node attrNode = createNode(attrName, newPropertyName);
                attrNode.setAttribute(true);
                attrNodes.add(attrNode);
       
       c) Call addNodes on XMLConfiguration,
                  conf.addNodes(attrPath, attrNodes);

I run this in a look for each new property I need to add. For first property, I get element count for the test.property as 3 (conf.getMaxIndex(key)) - so I insert at test.property(3), which is right, but for the second property I get element count as 5 --> This is wrong, it should have been 4 (because I just added 1).

I check the saved the configuration file after adding those two new properties and it looks wrong too. Here is what I get,

                 <test>
                          <property name="isOk">
                                  <value>true</value>
                                  <default>false</default>
                          </property>
                           <property name="intProperty">
                                  <value>900</value>
                                  <default>500</default>
                          </property>
                          <property extra="0" name="stringProperty">
                                  <value>Hi</value>
                                  <default>Bye</default>
                          </property>
                        <property>
                             <name>newFirst</name>
                        </property>
                        <property>
                             <value>first</value>
                         </property>
                         <property>
                             <name>newSecond</name>
                        </property>
                        <property>
                             <value>second</value>
                         </property>
                 </test>


The total element count for test.property gives me 7 ==> I was expecting 5.


There seems to have some code change in 1.5 releated to addNodes (for ex., CONFIGURATION-287). I'm not sure if I need to change the way I was calling addNodes before. It works fine with 1.3, but 1.5 completely fails on adding new properties.

I do need 1.5 for other bug fixes ( CONFIGURATION-268 and some other), but I can't use it until the addNodes behave correctly.

Marking this as blocker as I'm blocked because of this issue. If there is a workaround then please let me know.

    Fix Version/s: 1.6
          Summary: XMLConfiguration addNodes() not behaving correctly  (was: XMLConfiguration addNodes() not behaving correctly (in 1.5))

> XMLConfiguration addNodes() not behaving correctly
> --------------------------------------------------
>
>                 Key: CONFIGURATION-328
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-328
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.5
>         Environment: Linux, Apache Configuration 1.5
>            Reporter: vivek
>            Priority: Blocker
>             Fix For: 1.6
>
>
> Things used to work fine in 1.3, but now when I'm trying 1.5 my JUnit test suite is breaking when adding new properties. Here is what I'm doing,
> 1) I already have a configuration as following,
> {code:xml}
>  <test>
>   <property name="isOk">
>     <value>true</value>
>     <default>false</default>
>   </property>
>   <property name="intProperty">
>     <value>900</value>
>     <default>500</default>
>   </property>
>   <property extra="0" name="stringProperty">
>     <default>Bye</default>
>   </property>
> </test>
> {code}
> 2) Now I need to add two new properties under <test>,
> {code:xml}
> <property  name="newFirst">
>   <value>first</value>
> </property>
> <property name="newSecond">
>   <value>second</value>
> </property>
> {code}
> 3) Here is the code I'm using,
>         a) First create a new HierarchicalConfiguration.Node
> {code:java}
> private HierarchicalConfiguration.Node createNode(String name, Object value)  {
>     HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node(name);
>     node.setValue(value);
>     return node;
> }
> {code}
>                  
>        b) Add the node to the list
> {code:java}
> List<HierarchicalConfiguration.Node> attrNodes = new ArrayList<HierarchicalConfiguration.Node>();
> Node attrNode = createNode(attrName, newPropertyName);
> attrNode.setAttribute(true);
> attrNodes.add(attrNode);
> {code}
>        
>        c) Call addNodes on XMLConfiguration,
> {code:java}
>     conf.addNodes(attrPath, attrNodes);
> {code}
> I run this in a look for each new property I need to add. For first property, I get element count for the test.property as 3 (conf.getMaxIndex(key)) - so I insert at test.property(3), which is right, but for the second property I get element count as 5 --> This is wrong, it should have been 4 (because I just added 1).
> I check the saved the configuration file after adding those two new properties and it looks wrong too. Here is what I get,
> {code:xml}
> <test>
>   <property name="isOk">
>     <value>true</value>
>     <default>false</default>
>   </property>
>   <property name="intProperty">
>     <value>900</value>
>     <default>500</default>
>   </property>
>   <property extra="0" name="stringProperty">
>     <value>Hi</value>
>     default>Bye</default>
>   </property>
>   <property>
>     <name>newFirst</name>
>   </property>
>   <property>
>     <value>first</value>
>   </property>
>   <property>
>     <name>newSecond</name>
>   </property>
>   <property>
>     <value>second</value>
>   </property>
> </test>
> {code}
> The total element count for test.property gives me 7 ==> I was expecting 5.
> There seems to have some code change in 1.5 releated to addNodes (for ex., CONFIGURATION-287). I'm not sure if I need to change the way I was calling addNodes before. It works fine with 1.3, but 1.5 completely fails on adding new properties.
> I do need 1.5 for other bug fixes ( CONFIGURATION-268 and some other), but I can't use it until the addNodes behave correctly.
> Marking this as blocker as I'm blocked because of this issue. If there is a workaround then please let me know.

--
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] Issue Comment Edited: (CONFIGURATION-328) XMLConfiguration addNodes() not behaving correctly

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/CONFIGURATION-328?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12597767#action_12597767 ]

vivash edited comment on CONFIGURATION-328 at 5/18/08 11:25 AM:
---------------------------------------------------------------

Looks like the attribute is getting added as new tag,


{code:xml}
<property>
<name>newFirst</name>
</property>
<property>
<value>first</value>
</property>
{code}

is supposed to be,


{code:xml}
 <property name="newFirst">
     <value>first</value>
 </property>
{code}

In my code,

1) I first add the <property> tag under the <test> element - by calling conf.addNodes
2) Then I add the name attribute to the newly added property - again by calling conf.addNodes
3) Then I add the value tag under property - again by calling conf.addNodes

I do create a new HierarchicalConfiguration.Node every time to add it.  

It all used to work fine in 1.3, but it's failing in 1.5.

Note, my reloading strategy is false - not sure if that has anything to do with this.

      was (Author: vivash):
    Looks like the attribute is getting added as new tag,

<property>
<name>newFirst</name>
</property>
<property>
<value>first</value>
</property>

is supposed to be,

 <property name="newFirst">
     <value>first</value>
 </property>

In my code,

1) I first add the <property> tag under the <test> element - by calling conf.addNodes
2) Then I add the name attribute to the newly added property - again by calling conf.addNodes
3) Then I add the value tag under property - again by calling conf.addNodes

I do create a new HierarchicalConfiguration.Node every time to add it.  

It all used to work fine in 1.3, but it's failing in 1.5.

Note, my reloading strategy is false - not sure if that has anything to do with this.
 

> XMLConfiguration addNodes() not behaving correctly
> --------------------------------------------------
>
>                 Key: CONFIGURATION-328
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-328
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.5
>         Environment: Linux, Apache Configuration 1.5
>            Reporter: vivek
>            Priority: Blocker
>             Fix For: 1.6
>
>
> Things used to work fine in 1.3, but now when I'm trying 1.5 my JUnit test suite is breaking when adding new properties. Here is what I'm doing,
> 1) I already have a configuration as following,
> {code:xml}
>  <test>
>   <property name="isOk">
>     <value>true</value>
>     <default>false</default>
>   </property>
>   <property name="intProperty">
>     <value>900</value>
>     <default>500</default>
>   </property>
>   <property extra="0" name="stringProperty">
>     <default>Bye</default>
>   </property>
> </test>
> {code}
> 2) Now I need to add two new properties under <test>,
> {code:xml}
> <property  name="newFirst">
>   <value>first</value>
> </property>
> <property name="newSecond">
>   <value>second</value>
> </property>
> {code}
> 3) Here is the code I'm using,
>         a) First create a new HierarchicalConfiguration.Node
> {code:java}
> private HierarchicalConfiguration.Node createNode(String name, Object value)  {
>     HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node(name);
>     node.setValue(value);
>     return node;
> }
> {code}
>                  
>        b) Add the node to the list
> {code:java}
> List<HierarchicalConfiguration.Node> attrNodes = new ArrayList<HierarchicalConfiguration.Node>();
> Node attrNode = createNode(attrName, newPropertyName);
> attrNode.setAttribute(true);
> attrNodes.add(attrNode);
> {code}
>        
>        c) Call addNodes on XMLConfiguration,
> {code:java}
>     conf.addNodes(attrPath, attrNodes);
> {code}
> I run this in a look for each new property I need to add. For first property, I get element count for the test.property as 3 (conf.getMaxIndex(key)) - so I insert at test.property(3), which is right, but for the second property I get element count as 5 --> This is wrong, it should have been 4 (because I just added 1).
> I check the saved the configuration file after adding those two new properties and it looks wrong too. Here is what I get,
> {code:xml}
> <test>
>   <property name="isOk">
>     <value>true</value>
>     <default>false</default>
>   </property>
>   <property name="intProperty">
>     <value>900</value>
>     <default>500</default>
>   </property>
>   <property extra="0" name="stringProperty">
>     <value>Hi</value>
>     default>Bye</default>
>   </property>
>   <property>
>     <name>newFirst</name>
>   </property>
>   <property>
>     <value>first</value>
>   </property>
>   <property>
>     <name>newSecond</name>
>   </property>
>   <property>
>     <value>second</value>
>   </property>
> </test>
> {code}
> The total element count for test.property gives me 7 ==> I was expecting 5.
> There seems to have some code change in 1.5 releated to addNodes (for ex., CONFIGURATION-287). I'm not sure if I need to change the way I was calling addNodes before. It works fine with 1.3, but 1.5 completely fails on adding new properties.
> I do need 1.5 for other bug fixes ( CONFIGURATION-268 and some other), but I can't use it until the addNodes behave correctly.
> Marking this as blocker as I'm blocked because of this issue. If there is a workaround then please let me know.

--
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] Issue Comment Edited: (CONFIGURATION-328) XMLConfiguration addNodes() not behaving correctly

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/CONFIGURATION-328?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12597767#action_12597767 ]

vivash edited comment on CONFIGURATION-328 at 5/18/08 11:26 AM:
---------------------------------------------------------------

Looks like the attribute is getting added as new tag,


{code:xml}
<property>
     <name>newFirst</name>
</property>
<property>
     <value>first</value>
</property>
{code}

is supposed to be,


{code:xml}
 <property name="newFirst">
     <value>first</value>
 </property>
{code}

In my code,

1) I first add the <property> tag under the <test> element - by calling conf.addNodes
2) Then I add the name attribute to the newly added property - again by calling conf.addNodes
3) Then I add the value tag under property - again by calling conf.addNodes

I do create a new HierarchicalConfiguration.Node every time to add it.  

It all used to work fine in 1.3, but it's failing in 1.5.

Note, my reloading strategy is false - not sure if that has anything to do with this.

      was (Author: vivash):
    Looks like the attribute is getting added as new tag,


{code:xml}
<property>
<name>newFirst</name>
</property>
<property>
<value>first</value>
</property>
{code}

is supposed to be,


{code:xml}
 <property name="newFirst">
     <value>first</value>
 </property>
{code}

In my code,

1) I first add the <property> tag under the <test> element - by calling conf.addNodes
2) Then I add the name attribute to the newly added property - again by calling conf.addNodes
3) Then I add the value tag under property - again by calling conf.addNodes

I do create a new HierarchicalConfiguration.Node every time to add it.  

It all used to work fine in 1.3, but it's failing in 1.5.

Note, my reloading strategy is false - not sure if that has anything to do with this.
 

> XMLConfiguration addNodes() not behaving correctly
> --------------------------------------------------
>
>                 Key: CONFIGURATION-328
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-328
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.5
>         Environment: Linux, Apache Configuration 1.5
>            Reporter: vivek
>            Priority: Blocker
>             Fix For: 1.6
>
>
> Things used to work fine in 1.3, but now when I'm trying 1.5 my JUnit test suite is breaking when adding new properties. Here is what I'm doing,
> 1) I already have a configuration as following,
> {code:xml}
>  <test>
>   <property name="isOk">
>     <value>true</value>
>     <default>false</default>
>   </property>
>   <property name="intProperty">
>     <value>900</value>
>     <default>500</default>
>   </property>
>   <property extra="0" name="stringProperty">
>     <default>Bye</default>
>   </property>
> </test>
> {code}
> 2) Now I need to add two new properties under <test>,
> {code:xml}
> <property  name="newFirst">
>   <value>first</value>
> </property>
> <property name="newSecond">
>   <value>second</value>
> </property>
> {code}
> 3) Here is the code I'm using,
>         a) First create a new HierarchicalConfiguration.Node
> {code:java}
> private HierarchicalConfiguration.Node createNode(String name, Object value)  {
>     HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node(name);
>     node.setValue(value);
>     return node;
> }
> {code}
>                  
>        b) Add the node to the list
> {code:java}
> List<HierarchicalConfiguration.Node> attrNodes = new ArrayList<HierarchicalConfiguration.Node>();
> Node attrNode = createNode(attrName, newPropertyName);
> attrNode.setAttribute(true);
> attrNodes.add(attrNode);
> {code}
>        
>        c) Call addNodes on XMLConfiguration,
> {code:java}
>     conf.addNodes(attrPath, attrNodes);
> {code}
> I run this in a look for each new property I need to add. For first property, I get element count for the test.property as 3 (conf.getMaxIndex(key)) - so I insert at test.property(3), which is right, but for the second property I get element count as 5 --> This is wrong, it should have been 4 (because I just added 1).
> I check the saved the configuration file after adding those two new properties and it looks wrong too. Here is what I get,
> {code:xml}
> <test>
>   <property name="isOk">
>     <value>true</value>
>     <default>false</default>
>   </property>
>   <property name="intProperty">
>     <value>900</value>
>     <default>500</default>
>   </property>
>   <property extra="0" name="stringProperty">
>     <value>Hi</value>
>     default>Bye</default>
>   </property>
>   <property>
>     <name>newFirst</name>
>   </property>
>   <property>
>     <value>first</value>
>   </property>
>   <property>
>     <name>newSecond</name>
>   </property>
>   <property>
>     <value>second</value>
>   </property>
> </test>
> {code}
> The total element count for test.property gives me 7 ==> I was expecting 5.
> There seems to have some code change in 1.5 releated to addNodes (for ex., CONFIGURATION-287). I'm not sure if I need to change the way I was calling addNodes before. It works fine with 1.3, but 1.5 completely fails on adding new properties.
> I do need 1.5 for other bug fixes ( CONFIGURATION-268 and some other), but I can't use it until the addNodes behave correctly.
> Marking this as blocker as I'm blocked because of this issue. If there is a workaround then please let me know.

--
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-328) XMLConfiguration addNodes() not behaving correctly

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/CONFIGURATION-328?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12597827#action_12597827 ]

vivek commented on CONFIGURATION-328:
-------------------------------------

Emmanuel,

   Could you let me know if there is any workaround for this issue or if I can do things differently to make it work? It would be nice if you can give me a patch that I can apply to my local build or let me know what needs to be changed in the XMLConfiguration so I can make my own build.

Thanks,
-vivek

> XMLConfiguration addNodes() not behaving correctly
> --------------------------------------------------
>
>                 Key: CONFIGURATION-328
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-328
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.5
>         Environment: Linux, Apache Configuration 1.5
>            Reporter: vivek
>            Priority: Blocker
>             Fix For: 1.6
>
>
> Things used to work fine in 1.3, but now when I'm trying 1.5 my JUnit test suite is breaking when adding new properties. Here is what I'm doing,
> 1) I already have a configuration as following,
> {code:xml}
>  <test>
>   <property name="isOk">
>     <value>true</value>
>     <default>false</default>
>   </property>
>   <property name="intProperty">
>     <value>900</value>
>     <default>500</default>
>   </property>
>   <property extra="0" name="stringProperty">
>     <default>Bye</default>
>   </property>
> </test>
> {code}
> 2) Now I need to add two new properties under <test>,
> {code:xml}
> <property  name="newFirst">
>   <value>first</value>
> </property>
> <property name="newSecond">
>   <value>second</value>
> </property>
> {code}
> 3) Here is the code I'm using,
>         a) First create a new HierarchicalConfiguration.Node
> {code:java}
> private HierarchicalConfiguration.Node createNode(String name, Object value)  {
>     HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node(name);
>     node.setValue(value);
>     return node;
> }
> {code}
>                  
>        b) Add the node to the list
> {code:java}
> List<HierarchicalConfiguration.Node> attrNodes = new ArrayList<HierarchicalConfiguration.Node>();
> Node attrNode = createNode(attrName, newPropertyName);
> attrNode.setAttribute(true);
> attrNodes.add(attrNode);
> {code}
>        
>        c) Call addNodes on XMLConfiguration,
> {code:java}
>     conf.addNodes(attrPath, attrNodes);
> {code}
> I run this in a look for each new property I need to add. For first property, I get element count for the test.property as 3 (conf.getMaxIndex(key)) - so I insert at test.property(3), which is right, but for the second property I get element count as 5 --> This is wrong, it should have been 4 (because I just added 1).
> I check the saved the configuration file after adding those two new properties and it looks wrong too. Here is what I get,
> {code:xml}
> <test>
>   <property name="isOk">
>     <value>true</value>
>     <default>false</default>
>   </property>
>   <property name="intProperty">
>     <value>900</value>
>     <default>500</default>
>   </property>
>   <property extra="0" name="stringProperty">
>     <value>Hi</value>
>     default>Bye</default>
>   </property>
>   <property>
>     <name>newFirst</name>
>   </property>
>   <property>
>     <value>first</value>
>   </property>
>   <property>
>     <name>newSecond</name>
>   </property>
>   <property>
>     <value>second</value>
>   </property>
> </test>
> {code}
> The total element count for test.property gives me 7 ==> I was expecting 5.
> There seems to have some code change in 1.5 releated to addNodes (for ex., CONFIGURATION-287). I'm not sure if I need to change the way I was calling addNodes before. It works fine with 1.3, but 1.5 completely fails on adding new properties.
> I do need 1.5 for other bug fixes ( CONFIGURATION-268 and some other), but I can't use it until the addNodes behave correctly.
> Marking this as blocker as I'm blocked because of this issue. If there is a workaround then please let me know.

--
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-328) XMLConfiguration addNodes() not behaving correctly

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/CONFIGURATION-328?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12597831#action_12597831 ]

Oliver Heger commented on CONFIGURATION-328:
--------------------------------------------

Vivek, can you please post your complete code for adding the new properties? Based on the fragments you provided I don't really see the parameters (especially the keys) you pass into the addNodes() method.

> XMLConfiguration addNodes() not behaving correctly
> --------------------------------------------------
>
>                 Key: CONFIGURATION-328
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-328
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.5
>         Environment: Linux, Apache Configuration 1.5
>            Reporter: vivek
>            Priority: Blocker
>             Fix For: 1.6
>
>
> Things used to work fine in 1.3, but now when I'm trying 1.5 my JUnit test suite is breaking when adding new properties. Here is what I'm doing,
> 1) I already have a configuration as following,
> {code:xml}
>  <test>
>   <property name="isOk">
>     <value>true</value>
>     <default>false</default>
>   </property>
>   <property name="intProperty">
>     <value>900</value>
>     <default>500</default>
>   </property>
>   <property extra="0" name="stringProperty">
>     <default>Bye</default>
>   </property>
> </test>
> {code}
> 2) Now I need to add two new properties under <test>,
> {code:xml}
> <property  name="newFirst">
>   <value>first</value>
> </property>
> <property name="newSecond">
>   <value>second</value>
> </property>
> {code}
> 3) Here is the code I'm using,
>         a) First create a new HierarchicalConfiguration.Node
> {code:java}
> private HierarchicalConfiguration.Node createNode(String name, Object value)  {
>     HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node(name);
>     node.setValue(value);
>     return node;
> }
> {code}
>                  
>        b) Add the node to the list
> {code:java}
> List<HierarchicalConfiguration.Node> attrNodes = new ArrayList<HierarchicalConfiguration.Node>();
> Node attrNode = createNode(attrName, newPropertyName);
> attrNode.setAttribute(true);
> attrNodes.add(attrNode);
> {code}
>        
>        c) Call addNodes on XMLConfiguration,
> {code:java}
>     conf.addNodes(attrPath, attrNodes);
> {code}
> I run this in a look for each new property I need to add. For first property, I get element count for the test.property as 3 (conf.getMaxIndex(key)) - so I insert at test.property(3), which is right, but for the second property I get element count as 5 --> This is wrong, it should have been 4 (because I just added 1).
> I check the saved the configuration file after adding those two new properties and it looks wrong too. Here is what I get,
> {code:xml}
> <test>
>   <property name="isOk">
>     <value>true</value>
>     <default>false</default>
>   </property>
>   <property name="intProperty">
>     <value>900</value>
>     <default>500</default>
>   </property>
>   <property extra="0" name="stringProperty">
>     <value>Hi</value>
>     default>Bye</default>
>   </property>
>   <property>
>     <name>newFirst</name>
>   </property>
>   <property>
>     <value>first</value>
>   </property>
>   <property>
>     <name>newSecond</name>
>   </property>
>   <property>
>     <value>second</value>
>   </property>
> </test>
> {code}
> The total element count for test.property gives me 7 ==> I was expecting 5.
> There seems to have some code change in 1.5 releated to addNodes (for ex., CONFIGURATION-287). I'm not sure if I need to change the way I was calling addNodes before. It works fine with 1.3, but 1.5 completely fails on adding new properties.
> I do need 1.5 for other bug fixes ( CONFIGURATION-268 and some other), but I can't use it until the addNodes behave correctly.
> Marking this as blocker as I'm blocked because of this issue. If there is a workaround then please let me know.

--
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-328) XMLConfiguration addNodes() not behaving correctly

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

    [ https://issues.apache.org/jira/browse/CONFIGURATION-328?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12597839#action_12597839 ]

vivek commented on CONFIGURATION-328:
-------------------------------------

Let's say we have an existing xml configuration,

{code:xml}
<ss>
 <test>
    <property name="testProperty">
         <value>test</value>
    <property>
 </test>
</ss>
{code}

Now I want add a new property under existing <test> tag,

{code:xml}
 <property name="vivekProperty">
   <value>vivek</value>
 </property>
{code}

I do following,

1) create a node,

{code:java}
  HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node("property");
  node.setValue(null);
{code}

2) Find the path where the "property" tag needs to be added. In my case it's "ss.test(0)"

3) I call addNodes on XMLConfiguration instance,

 {code:java}
    conf.addNodes(propertyPath, propertyNode);    
    //where propertyPath is ss.test(0) and propertyNode is one created in step 1
 {code}

4) I check how many property tags are under ss.test(0) - in this case it returns me 2 (1 was just added)

5) I create another node object for the name attribute of property,

 {code:java}
  HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node("name");
  node.setValue("vivekProperty);
  node.setAttribute(true);             //setting the node as attribute
 {code}

6) Find the path where this attribute needs to be added. In this case it's "ss.test(0).property(1)"

7) Add the node,
 
  {code:java}
    conf.addNodes(attrPath, attrNode);    
    //where attrPath is ss.test(0).property(1) and attrNode is one created in step 5
 {code}
   

8) Create another node for the value tag under property,

 {code:java}
  HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node("value");
  node.setValue(""vivek");
 {code}

9) Now, when I try to find the index of the newly added property ("property name="vivekProperty") I get -1. So instead of "ss.test(0).property(1)", I get "ss.test(0).property(-1)". -1 in my code basically means it couldn't find that.  <=== So this is wrong.

This is the code to get the index of the property with a specific attribute name. So I'm trying to find the index of the property with name="vivekProperty",

   {code:java}
                lookupProp = "ss.test(0).property";
                synchronized(conf){
                        elements = conf.configurationsAt(lookupProp);
                }
               
                for (Iterator it = elements.iterator(); it.hasNext();) {
                        HierarchicalConfiguration sub = (HierarchicalConfiguration) it
                                        .next();
                        if(sub != null){
                                String name = sub.getString("[@" + attrName + "]");
                                if(name != null){
                                        if (name.equals(propName)) {
                                                isPropFound = true;
                                                break;
                                        }
                                        index = index + 1;
                                }
                        }
                }
                if (!isPropFound) {
                        index = -1;
                }
     {code}

10) Add the node,

 {code:java}
    conf.addNodes(valuePath, valueNode);    
    //where valuePath is ss.test(0).property(-1) and valueNode is one created in step 8
 {code}
       

11) After all this call save on the XMLConfiguration

This in 1.5 is giving me structure like,

{code:xml}

<ss>
 <test>
    <property name="testProperty">
         <value>test</value>
    <property>
    <property>
       <name>vivekProperty</name>
    </property>
    <property>
       <value>vivek</value>
    </property>
 </test>
</ss>

{code}


I'm not sure if I need to do "addNode" 3 time to add this structure or can it be added in one shot. But, all this used to work fine with 1.3. In our application this is a service so I can call any of the above 3 add nodes individaully in case user may just want to add a new value to an existing property.

So the problem looks like is the code "node.setAttribute(true);" (in Step 5) is not seems to be doing the right thing. Instead of adding a attribute name, it's adding a new element name under property, which doesn't work in my case.
     
     

> XMLConfiguration addNodes() not behaving correctly
> --------------------------------------------------
>
>                 Key: CONFIGURATION-328
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-328
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.5
>         Environment: Linux, Apache Configuration 1.5
>            Reporter: vivek
>            Priority: Blocker
>             Fix For: 1.6
>
>
> Things used to work fine in 1.3, but now when I'm trying 1.5 my JUnit test suite is breaking when adding new properties. Here is what I'm doing,
> 1) I already have a configuration as following,
> {code:xml}
>  <test>
>   <property name="isOk">
>     <value>true</value>
>     <default>false</default>
>   </property>
>   <property name="intProperty">
>     <value>900</value>
>     <default>500</default>
>   </property>
>   <property extra="0" name="stringProperty">
>     <default>Bye</default>
>   </property>
> </test>
> {code}
> 2) Now I need to add two new properties under <test>,
> {code:xml}
> <property  name="newFirst">
>   <value>first</value>
> </property>
> <property name="newSecond">
>   <value>second</value>
> </property>
> {code}
> 3) Here is the code I'm using,
>         a) First create a new HierarchicalConfiguration.Node
> {code:java}
> private HierarchicalConfiguration.Node createNode(String name, Object value)  {
>     HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node(name);
>     node.setValue(value);
>     return node;
> }
> {code}
>                  
>        b) Add the node to the list
> {code:java}
> List<HierarchicalConfiguration.Node> attrNodes = new ArrayList<HierarchicalConfiguration.Node>();
> Node attrNode = createNode(attrName, newPropertyName);
> attrNode.setAttribute(true);
> attrNodes.add(attrNode);
> {code}
>        
>        c) Call addNodes on XMLConfiguration,
> {code:java}
>     conf.addNodes(attrPath, attrNodes);
> {code}
> I run this in a look for each new property I need to add. For first property, I get element count for the test.property as 3 (conf.getMaxIndex(key)) - so I insert at test.property(3), which is right, but for the second property I get element count as 5 --> This is wrong, it should have been 4 (because I just added 1).
> I check the saved the configuration file after adding those two new properties and it looks wrong too. Here is what I get,
> {code:xml}
> <test>
>   <property name="isOk">
>     <value>true</value>
>     <default>false</default>
>   </property>
>   <property name="intProperty">
>     <value>900</value>
>     <default>500</default>
>   </property>
>   <property extra="0" name="stringProperty">
>     <value>Hi</value>
>     default>Bye</default>
>   </property>
>   <property>
>     <name>newFirst</name>
>   </property>
>   <property>
>     <value>first</value>
>   </property>
>   <property>
>     <name>newSecond</name>
>   </property>
>   <property>
>     <value>second</value>
>   </property>
> </test>
> {code}
> The total element count for test.property gives me 7 ==> I was expecting 5.
> There seems to have some code change in 1.5 releated to addNodes (for ex., CONFIGURATION-287). I'm not sure if I need to change the way I was calling addNodes before. It works fine with 1.3, but 1.5 completely fails on adding new properties.
> I do need 1.5 for other bug fixes ( CONFIGURATION-268 and some other), but I can't use it until the addNodes behave correctly.
> Marking this as blocker as I'm blocked because of this issue. If there is a workaround then please let me know.

--
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-328) XMLConfiguration addNodes() not behaving correctly

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

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

vivek updated CONFIGURATION-328:
--------------------------------

    Priority: Major  (was: Blocker)

I tried adding attribute as part of the property element itself,

{code:java}
nodeToAdd.addAttribute(new DefaultConfigurationNode(attrName, newPropertyName));
{code}

This seems to work fine. So, instead of using "setAttribute(true)" if I just do addAttribute it seems to work fine. May be that's the right way.

I'll leave to you guys to see whether there is any issue in 1.5 or it used to work in 1.3 because of some bug, which has been fixed in 1.5.

For me the workaround is working fine now.

> XMLConfiguration addNodes() not behaving correctly
> --------------------------------------------------
>
>                 Key: CONFIGURATION-328
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-328
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.5
>         Environment: Linux, Apache Configuration 1.5
>            Reporter: vivek
>             Fix For: 1.6
>
>
> Things used to work fine in 1.3, but now when I'm trying 1.5 my JUnit test suite is breaking when adding new properties. Here is what I'm doing,
> 1) I already have a configuration as following,
> {code:xml}
>  <test>
>   <property name="isOk">
>     <value>true</value>
>     <default>false</default>
>   </property>
>   <property name="intProperty">
>     <value>900</value>
>     <default>500</default>
>   </property>
>   <property extra="0" name="stringProperty">
>     <default>Bye</default>
>   </property>
> </test>
> {code}
> 2) Now I need to add two new properties under <test>,
> {code:xml}
> <property  name="newFirst">
>   <value>first</value>
> </property>
> <property name="newSecond">
>   <value>second</value>
> </property>
> {code}
> 3) Here is the code I'm using,
>         a) First create a new HierarchicalConfiguration.Node
> {code:java}
> private HierarchicalConfiguration.Node createNode(String name, Object value)  {
>     HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node(name);
>     node.setValue(value);
>     return node;
> }
> {code}
>                  
>        b) Add the node to the list
> {code:java}
> List<HierarchicalConfiguration.Node> attrNodes = new ArrayList<HierarchicalConfiguration.Node>();
> Node attrNode = createNode(attrName, newPropertyName);
> attrNode.setAttribute(true);
> attrNodes.add(attrNode);
> {code}
>        
>        c) Call addNodes on XMLConfiguration,
> {code:java}
>     conf.addNodes(attrPath, attrNodes);
> {code}
> I run this in a look for each new property I need to add. For first property, I get element count for the test.property as 3 (conf.getMaxIndex(key)) - so I insert at test.property(3), which is right, but for the second property I get element count as 5 --> This is wrong, it should have been 4 (because I just added 1).
> I check the saved the configuration file after adding those two new properties and it looks wrong too. Here is what I get,
> {code:xml}
> <test>
>   <property name="isOk">
>     <value>true</value>
>     <default>false</default>
>   </property>
>   <property name="intProperty">
>     <value>900</value>
>     <default>500</default>
>   </property>
>   <property extra="0" name="stringProperty">
>     <value>Hi</value>
>     default>Bye</default>
>   </property>
>   <property>
>     <name>newFirst</name>
>   </property>
>   <property>
>     <value>first</value>
>   </property>
>   <property>
>     <name>newSecond</name>
>   </property>
>   <property>
>     <value>second</value>
>   </property>
> </test>
> {code}
> The total element count for test.property gives me 7 ==> I was expecting 5.
> There seems to have some code change in 1.5 releated to addNodes (for ex., CONFIGURATION-287). I'm not sure if I need to change the way I was calling addNodes before. It works fine with 1.3, but 1.5 completely fails on adding new properties.
> I do need 1.5 for other bug fixes ( CONFIGURATION-268 and some other), but I can't use it until the addNodes behave correctly.
> Marking this as blocker as I'm blocked because of this issue. If there is a workaround then please let me know.

--
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-328) XMLConfiguration addNodes() not behaving correctly

JIRA jira@apache.org
In reply to this post by JIRA jira@apache.org

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

Oliver Heger resolved CONFIGURATION-328.
----------------------------------------

    Resolution: Fixed

There was indeed a bug in XMLConfiguration, which prevented attribute nodes from being added using the addNodes() method. A fix was applied. Thank you for spotting this.

Regarding your use case, I think you do not need the addNodes() method, but you can achieve the same effect in an easer way using addProperty(). For instance, in the unit test I wrote to demonstrate this bug I created a structure similar to your test configuration with the following code:

{code}
conf.addProperty("testAddNodes.property[@name]", "prop1");
conf.addProperty("testAddNodes.property(0).value", "value1");
conf.addProperty("testAddNodes.property(-1)[@name]", "prop2");
conf.addProperty("testAddNodes.property(1).value", "value2");
{code}

This creates two <property> structures. If you look at the last two statements, the first one creates a new _property_ node and the name attribute at the same time. The index -1 means that a new node is to be created. The following statement adds the _value_ child node. Here the index of the last _property_ node must be specified. Hope that helps.

> XMLConfiguration addNodes() not behaving correctly
> --------------------------------------------------
>
>                 Key: CONFIGURATION-328
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-328
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.5
>         Environment: Linux, Apache Configuration 1.5
>            Reporter: vivek
>            Assignee: Oliver Heger
>             Fix For: 1.6
>
>
> Things used to work fine in 1.3, but now when I'm trying 1.5 my JUnit test suite is breaking when adding new properties. Here is what I'm doing,
> 1) I already have a configuration as following,
> {code:xml}
>  <test>
>   <property name="isOk">
>     <value>true</value>
>     <default>false</default>
>   </property>
>   <property name="intProperty">
>     <value>900</value>
>     <default>500</default>
>   </property>
>   <property extra="0" name="stringProperty">
>     <default>Bye</default>
>   </property>
> </test>
> {code}
> 2) Now I need to add two new properties under <test>,
> {code:xml}
> <property  name="newFirst">
>   <value>first</value>
> </property>
> <property name="newSecond">
>   <value>second</value>
> </property>
> {code}
> 3) Here is the code I'm using,
>         a) First create a new HierarchicalConfiguration.Node
> {code:java}
> private HierarchicalConfiguration.Node createNode(String name, Object value)  {
>     HierarchicalConfiguration.Node node = new HierarchicalConfiguration.Node(name);
>     node.setValue(value);
>     return node;
> }
> {code}
>                  
>        b) Add the node to the list
> {code:java}
> List<HierarchicalConfiguration.Node> attrNodes = new ArrayList<HierarchicalConfiguration.Node>();
> Node attrNode = createNode(attrName, newPropertyName);
> attrNode.setAttribute(true);
> attrNodes.add(attrNode);
> {code}
>        
>        c) Call addNodes on XMLConfiguration,
> {code:java}
>     conf.addNodes(attrPath, attrNodes);
> {code}
> I run this in a look for each new property I need to add. For first property, I get element count for the test.property as 3 (conf.getMaxIndex(key)) - so I insert at test.property(3), which is right, but for the second property I get element count as 5 --> This is wrong, it should have been 4 (because I just added 1).
> I check the saved the configuration file after adding those two new properties and it looks wrong too. Here is what I get,
> {code:xml}
> <test>
>   <property name="isOk">
>     <value>true</value>
>     <default>false</default>
>   </property>
>   <property name="intProperty">
>     <value>900</value>
>     <default>500</default>
>   </property>
>   <property extra="0" name="stringProperty">
>     <value>Hi</value>
>     default>Bye</default>
>   </property>
>   <property>
>     <name>newFirst</name>
>   </property>
>   <property>
>     <value>first</value>
>   </property>
>   <property>
>     <name>newSecond</name>
>   </property>
>   <property>
>     <value>second</value>
>   </property>
> </test>
> {code}
> The total element count for test.property gives me 7 ==> I was expecting 5.
> There seems to have some code change in 1.5 releated to addNodes (for ex., CONFIGURATION-287). I'm not sure if I need to change the way I was calling addNodes before. It works fine with 1.3, but 1.5 completely fails on adding new properties.
> I do need 1.5 for other bug fixes ( CONFIGURATION-268 and some other), but I can't use it until the addNodes behave correctly.
> Marking this as blocker as I'm blocked because of this issue. If there is a workaround then please let me know.

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