commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Kraft (JIRA)" <j...@apache.org>
Subject [jira] Created: (CONFIGURATION-301) NullPointerException in XMLConfiguration.save() after creating it from HierarchicalConfiguration
Date Wed, 12 Dec 2007 11:24:43 GMT
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
            Priority: Minor


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/trunk@603551:
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.


Mime
View raw message