commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1300238 - in /commons/proper/io/trunk/src: main/java/org/apache/commons/io/input/CharSequenceInputStream.java test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
Date Tue, 13 Mar 2012 17:03:32 GMT
Author: sebb
Date: Tue Mar 13 17:03:32 2012
New Revision: 1300238

URL: http://svn.apache.org/viewvc?rev=1300238&view=rev
Log:
Fix occasional test failure - should always return 0 for read length == 0

Modified:
    commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/CharSequenceInputStream.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/CharSequenceInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/CharSequenceInputStream.java?rev=1300238&r1=1300237&r2=1300238&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/CharSequenceInputStream.java
(original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/CharSequenceInputStream.java
Tue Mar 13 17:03:32 2012
@@ -117,7 +117,10 @@ public class CharSequenceInputStream ext
         if (len < 0 || (off + len) > b.length) {
             throw new IndexOutOfBoundsException("Array Size=" + b.length +
                     ", offset=" + off + ", length=" + len);
-        }        
+        }
+        if (len == 0) {
+            return 0; // must return 0 for zero length read
+        }
         if (!this.bbuf.hasRemaining() && !this.cbuf.hasRemaining()) {
             return -1;
         }

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java?rev=1300238&r1=1300237&r2=1300238&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
(original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/CharSequenceInputStreamTest.java
Tue Mar 13 17:03:32 2012
@@ -109,6 +109,13 @@ public class CharSequenceInputStreamTest
         byte[] bytes = new byte[30];
         assertEquals(0, r.read(bytes, 0, 0));
     }
+
+    @Test
+    public void testReadZeroEmptyString() throws Exception {
+        InputStream r = new CharSequenceInputStream("", "UTF-8");
+        byte[] bytes = new byte[30];
+        assertEquals(0, r.read(bytes, 0, 0));
+    }
     
     @Test
     public void testCharsetMismatchInfiniteLoop() throws IOException {



Mime
View raw message