commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Daniel Kraft (JIRA)" <>
Subject [jira] Created: (CONFIGURATION-301) NullPointerException in after creating it from HierarchicalConfiguration
Date Wed, 12 Dec 2007 11:24:43 GMT
NullPointerException in after creating it from HierarchicalConfiguration

                 Key: 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");;
		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");;

Here comes a simple configuration file to use (test.xml):
<?xml version="1.0" encoding="utf-8"?>
    <c />

And here a Stracktrace against
Exception in thread "main" java.lang.NullPointerException
	at org.apache.commons.configuration.XMLConfiguration$XMLBuilderVisitor.insert(
	at org.apache.commons.configuration.HierarchicalConfiguration$BuilderVisitor.visitBeforeChildren(
	at org.apache.commons.configuration.HierarchicalConfiguration$Node.visit(
	at org.apache.commons.configuration.XMLConfiguration$XMLBuilderVisitor.processDocument(
	at org.apache.commons.configuration.XMLConfiguration.createDocument(
	at org.apache.commons.configuration.AbstractHierarchicalFileConfiguration$
	at Tester.main(

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

View raw message