Uploaded image for project: 'Commons Configuration'
  1. Commons Configuration
  2. CONFIGURATION-301

NullPointerException in XMLConfiguration.save() after creating it from HierarchicalConfiguration

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.4, 1.5, Nightly Builds
    • 1.6
    • None
    • None
    • Sun JDK 1.5.0-13 on Debian GNU/Linux

    Description

      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)

      Attachments

        Activity

          People

            oheger Oliver Heger
            da_kraft Daniel Kraft
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: