harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From odea...@apache.org
Subject svn commit: r775075 - in /harmony/enhanced/classlib/trunk/modules/nio/src: main/java/common/java/nio/CharBuffer.java test/java/common/org/apache/harmony/nio/tests/java/nio/CharBufferTest.java
Date Fri, 15 May 2009 09:47:07 GMT
Author: odeakin
Date: Fri May 15 09:47:07 2009
New Revision: 775075

URL: http://svn.apache.org/viewvc?rev=775075&view=rev
Log:
Apply patch for HARMONY-6209 ([classlib][nio] java.nio.CharBuffer.read(CharBuffer target)
throws an IllegalArgumentException while RI doesn't in a special scenario)

Modified:
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/CharBuffer.java
    harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/CharBufferTest.java

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/CharBuffer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/CharBuffer.java?rev=775075&r1=775074&r2=775075&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/CharBuffer.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/CharBuffer.java
Fri May 15 09:47:07 2009
@@ -782,16 +782,22 @@
      *         read from this buffer.
      */
     public int read(CharBuffer target) throws IOException {
+        int remaining = remaining();
         if (target == this) {
+            if (remaining == 0) {
+                return -1;
+            }
             throw new IllegalArgumentException();
         }
-        if (remaining() == 0) {
-            return target.remaining() == 0 ? 0 : -1;
+        if (remaining == 0) {
+            return limit > 0 && target.remaining() == 0 ? 0 : -1;
         }
-        int result = Math.min(target.remaining(), remaining());
-        char[] chars = new char[result];
-        get(chars);
-        target.put(chars);
-        return result;
+        remaining = Math.min(target.remaining(), remaining);
+        if (remaining > 0) {
+            char[] chars = new char[remaining];
+            get(chars);
+            target.put(chars);
+        }
+        return remaining;
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/CharBufferTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/CharBufferTest.java?rev=775075&r1=775074&r2=775075&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/CharBufferTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/nio/tests/java/nio/CharBufferTest.java
Fri May 15 09:47:07 2009
@@ -1039,6 +1039,30 @@
 		}
 	}
 
+    public void testRead_scenario1() throws Exception {
+        char[] charArray = new char[] { 'a', 'b' };
+        CharBuffer charBuffer = CharBuffer.wrap(charArray);
+        try {
+            charBuffer.read(charBuffer);
+            fail("should throw IllegalArgumentException");
+        } catch (IllegalArgumentException e) {
+            // expected
+        }
+        charBuffer.put(charArray);
+        assertEquals(-1, charBuffer.read(charBuffer));
+    }
+
+    public void testRead_scenario2() throws Exception {
+        CharBuffer charBufferA = CharBuffer.allocate(0);
+        CharBuffer allocateBuffer = CharBuffer.allocate(1);
+        CharBuffer charBufferB = CharBuffer.wrap(allocateBuffer);
+        assertEquals(-1, charBufferA.read(charBufferB));
+
+        allocateBuffer.append(allocateBuffer);
+        charBufferB = CharBuffer.wrap(allocateBuffer);
+        assertEquals(-1, charBufferA.read(charBufferB));
+    }
+
 	public void testIsDirect() {
 		assertFalse(buf.isDirect());
 	}



Mime
View raw message