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

Oliver Heger updated CONFIGURATION-301:
---------------------------------------

    Fix Version/s: 1.6
         Assignee: Oliver Heger

You are right, I can reproduce the bug. The problem seems to be that the root 
element's reference (which should point to the corresponding XML element) is 
not correctly initialized. I will have a look.

> NullPointerException in XMLConfiguration.save() after creating it from 
> HierarchicalConfiguration
> ------------------------------------------------------------------------------------------------
>
>                 Key: CONFIGURATION-301
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-301
>             Project: Commons Configuration
>          Issue Type: Bug
>    Affects Versions: 1.4, Nightly Builds, 1.5
>         Environment: Sun JDK 1.5.0-13 on Debian GNU/Linux
>            Reporter: Daniel Kraft
>            Assignee: Oliver Heger
>            Priority: Minor
>             Fix For: 1.6
>
>
> The subject says it all, the following code reproduces it. The two commented 
> lines work around the bug: The first one fixes the NullPointerException, but 
> destroys the name of the root element; the second arranges for the name being 
> recreated.
> import org.apache.commons.configuration.ConfigurationException;
> import org.apache.commons.configuration.SubnodeConfiguration;
> import org.apache.commons.configuration.XMLConfiguration;
> public class Tester {
>       public static void main(String[] args) throws ConfigurationException {
>               XMLConfiguration c1 = new XMLConfiguration("test.xml");
>               c1.save(System.out);
>               SubnodeConfiguration c1sub = c1.configurationAt("b");
>               XMLConfiguration c2 = new XMLConfiguration(c1sub);
>               // This fixes the error: c2.getRootNode().setName(null);
>               // This fixes the name loss: c2.setRootElementName("b");
>               c2.save(System.out);
>       }
> }
> Here comes a simple configuration file to use (test.xml):
> <?xml version="1.0" encoding="utf-8"?>
> <a>
>   <b>
>     <c />
>   </b>
> </a>
> And here a Stracktrace against 
> http://svn.apache.org/repos/asf/commons/proper/configuration/[EMAIL 
> PROTECTED]:
> Exception in thread "main" java.lang.NullPointerException
>       at 
> org.apache.commons.configuration.XMLConfiguration$XMLBuilderVisitor.insert(XMLConfiguration.java:1188)
>       at 
> org.apache.commons.configuration.HierarchicalConfiguration$BuilderVisitor.visitBeforeChildren(HierarchicalConfiguration.java:1642)
>       at 
> org.apache.commons.configuration.HierarchicalConfiguration$Node.visit(HierarchicalConfiguration.java:1319)
>       at 
> org.apache.commons.configuration.XMLConfiguration$XMLBuilderVisitor.processDocument(XMLConfiguration.java:1153)
>       at 
> org.apache.commons.configuration.XMLConfiguration.createDocument(XMLConfiguration.java:621)
>       at 
> org.apache.commons.configuration.XMLConfiguration.save(XMLConfiguration.java:711)
>       at 
> org.apache.commons.configuration.AbstractHierarchicalFileConfiguration$FileConfigurationDelegate.save(AbstractHierarchicalFileConfiguration.java:448)
>       at 
> org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:544)
>       at 
> org.apache.commons.configuration.AbstractFileConfiguration.save(AbstractFileConfiguration.java:511)
>       at 
> org.apache.commons.configuration.AbstractHierarchicalFileConfiguration.save(AbstractHierarchicalFileConfiguration.java:214)
>       at Tester.main(Tester.java:14)

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

Reply via email to