sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1532359 - in /sis/branches/JDK7/core/sis-utility/src: main/java/org/apache/sis/io/LineAppender.java main/java/org/apache/sis/util/logging/MonolineFormatter.java test/java/org/apache/sis/io/LineAppenderTest.java
Date Tue, 15 Oct 2013 14:30:29 GMT
Author: desruisseaux
Date: Tue Oct 15 14:30:28 2013
New Revision: 1532359

URL: http://svn.apache.org/r1532359
Log:
Fixed an IndexOutOfBoundsException when a call to LineAppender.flush() is interleaved between
two append (SIS-140).

Modified:
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/LineAppender.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/io/LineAppenderTest.java

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/LineAppender.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/LineAppender.java?rev=1532359&r1=1532358&r2=1532359&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/LineAppender.java [UTF-8]
(original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/io/LineAppender.java [UTF-8]
Tue Oct 15 14:30:28 2013
@@ -56,7 +56,7 @@ import org.apache.sis.internal.util.X364
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.00)
- * @version 0.3
+ * @version 0.4
  * @module
  */
 @Decorator(Appendable.class)
@@ -560,6 +560,7 @@ searchHyp:  for (int i=buffer.length(); 
     public void flush() throws IOException {
         out.append(buffer);
         buffer.setLength(0);
+        printableLength = 0;
         IO.flush(out);
     }
 

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java?rev=1532359&r1=1532358&r2=1532359&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/util/logging/MonolineFormatter.java
[UTF-8] Tue Oct 15 14:30:28 2013
@@ -101,7 +101,7 @@ import org.apache.sis.util.Debug;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-2.0)
- * @version 0.3
+ * @version 0.4
  * @module
  *
  * @see SimpleFormatter
@@ -600,8 +600,8 @@ loop:   for (int i=0; ; i++) {
                 buffer.append(colorAt(level));
             }
             final int offset = buffer.length();
-            buffer.append(level.getLocalizedName());
-            buffer.append(CharSequences.spaces(levelWidth - (buffer.length() - offset)));
+            buffer.append(level.getLocalizedName())
+                  .append(CharSequences.spaces(levelWidth - (buffer.length() - offset)));
             margin += buffer.length() - offset;
             if (colors) {
                 buffer.append(X364.BACKGROUND_DEFAULT.sequence());
@@ -630,7 +630,6 @@ loop:   for (int i=0; ; i++) {
                     break;
                 }
             }
-            source = source.replace('$', '.');
             if (colors && emphase) {
                 buffer.append(X364.BOLD.sequence());
             }

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/io/LineAppenderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/io/LineAppenderTest.java?rev=1532359&r1=1532358&r2=1532359&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/io/LineAppenderTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/io/LineAppenderTest.java
[UTF-8] Tue Oct 15 14:30:28 2013
@@ -19,6 +19,7 @@ package org.apache.sis.io;
 import java.io.IOException;
 import org.apache.sis.test.DependsOn;
 import org.junit.Before;
+import org.junit.Test;
 
 import static org.junit.Assert.*;
 
@@ -30,7 +31,7 @@ import static org.junit.Assert.*;
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.00)
- * @version 0.3
+ * @version 0.4
  * @module
  */
 @DependsOn({
@@ -73,4 +74,22 @@ public strictfp class LineAppenderTest e
         assertSame(f, f.append(lineSeparator + "ses illusions."));
         assertOutputEquals("Le vrai policitien, c'est celui qui arrive à garder son idéal
tout en perdant ses illusions.");
     }
+
+    /**
+     * Tests a call to {@link LineAppender#flush()} interleaved between two lines,
+     * where the second line begin with a tabulation.
+     *
+     * @throws IOException Should never happen, since we are writing in a {@link StringBuilder}.
+     *
+     * @see <a href="https://issues.apache.org/jira/browse/SIS-140">SIS-140</a>
+     */
+    @Test
+    public void testInterleavedFlush() throws IOException {
+        final LineAppender f = (LineAppender) appender;
+        f.setTabulationWidth(4);
+        f.append("A");
+        f.flush();
+        f.append("\tB");
+        assertOutputEquals(f.isTabulationExpanded() ? "A   B" : "A\tB");
+    }
 }



Mime
View raw message