commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1772114 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration2/PropertiesConfigurationLayout.java test/java/org/apache/commons/configuration2/TestPropertiesConfigurationLayout.java
Date Wed, 30 Nov 2016 20:52:24 GMT
Author: oheger
Date: Wed Nov 30 20:52:24 2016
New Revision: 1772114

URL: http://svn.apache.org/viewvc?rev=1772114&view=rev
Log:
[CONFIGURATION-644] Fix for a duplicated header comment.

Under certain circumstances, the header comment managed by
PropertiesConfigurationLayout gets duplicated. This commit fixes
this problem.

Thanks to Andrew DeMaria for the patch.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/PropertiesConfigurationLayout.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestPropertiesConfigurationLayout.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/PropertiesConfigurationLayout.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/PropertiesConfigurationLayout.java?rev=1772114&r1=1772113&r2=1772114&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/PropertiesConfigurationLayout.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration2/PropertiesConfigurationLayout.java
Wed Nov 30 20:52:24 2016
@@ -796,8 +796,7 @@ public class PropertiesConfigurationLayo
      */
     private int checkHeaderComment(List<String> commentLines)
     {
-        if (loadCounter == 1 && getHeaderComment() == null
-                && layoutData.isEmpty())
+        if (loadCounter == 1 && layoutData.isEmpty())
         {
             // This is the first comment. Search for blanc lines.
             int index = commentLines.size() - 1;
@@ -806,7 +805,10 @@ public class PropertiesConfigurationLayo
             {
                 index--;
             }
-            setHeaderComment(extractComment(commentLines, 0, index - 1));
+            if (getHeaderComment() == null)
+            {
+                setHeaderComment(extractComment(commentLines, 0, index - 1));
+            }
             return index + 1;
         }
         else

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestPropertiesConfigurationLayout.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestPropertiesConfigurationLayout.java?rev=1772114&r1=1772113&r2=1772114&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestPropertiesConfigurationLayout.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration2/TestPropertiesConfigurationLayout.java
Wed Nov 30 20:52:24 2016
@@ -230,6 +230,26 @@ public class TestPropertiesConfiguration
     }
 
     /**
+     * Tests if a header comment containing blanc lines is correctly detected and doesn't
overflow into the property
+     * comment in the case that the header comment is already set
+     */
+    @Test
+    public void testHeaderCommentWithBlancsAndPresetHeaderComment() throws ConfigurationException
+    {
+        String presetHeaderComment = "preset" + TEST_COMMENT + CRNORM + CRNORM + TEST_COMMENT;
+        builder.addComment(TEST_COMMENT);
+        builder.addComment(null);
+        builder.addComment(TEST_COMMENT);
+        builder.addComment(null);
+        builder.addProperty(TEST_KEY, TEST_VALUE);
+        layout.setHeaderComment(presetHeaderComment);
+        layout.load(config, builder.getReader());
+        assertEquals("Wrong header comment", presetHeaderComment,
+                     layout.getCanonicalHeaderComment(false));
+        assertNull("Wrong comment for property", layout.getComment(TEST_KEY));
+    }
+
+    /**
      * Tests if a header comment is correctly detected when it contains blanc
      * lines and the first property has a comment, too.
      */



Mime
View raw message