commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r603841 - in /commons/proper/configuration/trunk: src/java/org/apache/commons/configuration/XMLConfiguration.java src/test/org/apache/commons/configuration/TestXMLConfiguration.java xdocs/changes.xml
Date Thu, 13 Dec 2007 06:51:17 GMT
Author: oheger
Date: Wed Dec 12 22:51:15 2007
New Revision: 603841

URL: http://svn.apache.org/viewvc?rev=603841&view=rev
Log:
CONFIGURATION-301: Fix for NPE when saving an XMLConfiguration constructed from a HierarchicalConfiguration

Modified:
    commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
    commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
    commons/proper/configuration/trunk/xdocs/changes.xml

Modified: commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java?rev=603841&r1=603840&r2=603841&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/java/org/apache/commons/configuration/XMLConfiguration.java
Wed Dec 12 22:51:15 2007
@@ -200,6 +200,7 @@
     {
         super(c);
         clearReferences(getRootNode());
+        setRootElementName(getRootNode().getName());
     }
 
     /**
@@ -1266,8 +1267,10 @@
          */
         private Element getElement(Node node)
         {
-            // special treatement for root node of the hierarchy
-            return (node.getName() != null) ? (Element) node.getReference() : document.getDocumentElement();
+            // special treatment for root node of the hierarchy
+            return (node.getName() != null && node.getReference() != null) ? (Element)
node
+                    .getReference()
+                    : document.getDocumentElement();
         }
     }
 

Modified: commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java?rev=603841&r1=603840&r2=603841&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestXMLConfiguration.java
Wed Dec 12 22:51:15 2007
@@ -1279,6 +1279,23 @@
     }
 
     /**
+     * Tests saving a configuration that was created from a hierarchical
+     * configuration. This test exposes bug CONFIGURATION-301.
+     */
+    public void testSaveAfterCreateWithCopyConstructor()
+            throws ConfigurationException
+    {
+        HierarchicalConfiguration hc = conf.configurationAt("element2");
+        conf = new XMLConfiguration(hc);
+        conf.save(testSaveConf);
+        XMLConfiguration checkConfig = new XMLConfiguration();
+        checkConfig.setFile(testSaveConf);
+        checkSavedConfig(checkConfig);
+        assertEquals("Wrong name of root element", "element2", checkConfig
+                .getRootElementName());
+    }
+
+    /**
      * Prepares a configuration object for testing a reload operation.
      *
      * @return the initialized configuration

Modified: commons/proper/configuration/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/xdocs/changes.xml?rev=603841&r1=603840&r2=603841&view=diff
==============================================================================
--- commons/proper/configuration/trunk/xdocs/changes.xml (original)
+++ commons/proper/configuration/trunk/xdocs/changes.xml Wed Dec 12 22:51:15 2007
@@ -23,6 +23,11 @@
 
   <body>
     <release version="1.6" date="in SVN" description="">
+      <action dev="oheger" type="fix" issue="CONFIGURATION-301">
+        Fixed a NullPointerException that could be thrown under certain
+        circumstances when saving an XMLConfiguration that was created using
+        the constructor that takes a HierarchicalConfiguration.
+      </action>
     </release>
 
     <release version="1.5" date="2007-11-24" description="Many smaller bugfixes">



Mime
View raw message