commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1806819 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration2/INIConfiguration.java test/java/org/apache/commons/configuration2/TestINIConfiguration.java
Date Thu, 31 Aug 2017 16:03:06 GMT
Author: oheger
Date: Thu Aug 31 16:03:06 2017
New Revision: 1806819

URL: http://svn.apache.org/viewvc?rev=1806819&view=rev
Log:
[CONFIGURATION-671] Fixed handling of empty sections in INIConfiguration.

Saving of an INIConfiguration with an empty section caused a NPE. The
cause was that nodes without children were not detected as section
nodes. Now a different criterion is used.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/INIConfiguration.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestINIConfiguration.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/INIConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/INIConfiguration.java?rev=1806819&r1=1806818&r2=1806819&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/INIConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/INIConfiguration.java
Thu Aug 31 16:03:06 2017
@@ -212,6 +212,10 @@ import org.apache.commons.configuration2
  * <a href="http://commons.apache.org/proper/commons-configuration/userguide/howto_basicfeatures.html">
  * Basic features and AbstractConfiguration</a> of the user's guide.
  * </p>
+ * <p>
+ * Note that this configuration does not support properties with null values.
+ * Such properties are considered to be section nodes.
+ * </p>
  *
  * @author <a
  *         href="http://commons.apache.org/configuration/team-list.html">Commons
@@ -942,7 +946,7 @@ public class INIConfiguration extends Ba
      */
     private static boolean isSectionNode(ImmutableNode node)
     {
-        return !node.getChildren().isEmpty();
+        return node.getValue() == null;
     }
 
     /**

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestINIConfiguration.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestINIConfiguration.java?rev=1806819&r1=1806818&r2=1806819&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestINIConfiguration.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestINIConfiguration.java
Thu Aug 31 16:03:06 2017
@@ -1224,6 +1224,27 @@ public class TestINIConfiguration
     }
 
     /**
+     * Tests whether an empty section can be saved. This is related to
+     * CONFIGURATION-671.
+     */
+    @Test
+    public void testWriteEmptySection()
+            throws ConfigurationException, IOException
+    {
+        final String section = "[EmptySection]";
+        INIConfiguration config = setUpConfig(section);
+        assertEquals("Wrong number of sections", 1,
+                config.getSections().size());
+        assertTrue("Section not found",
+                config.getSections().contains("EmptySection"));
+
+        StringWriter writer = new StringWriter();
+        config.write(writer);
+        assertEquals("Wrong saved configuration",
+                section + LINE_SEPARATOR + LINE_SEPARATOR, writer.toString());
+    }
+
+    /**
      * A thread class for testing concurrent access to the global section.
      */
     private static class GlobalSectionTestThread extends Thread



Mime
View raw message