You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by py...@apache.org on 2007/04/12 11:50:41 UTC

svn commit: r527865 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/BufferedOutputStream.java test/java/tests/api/java/io/BufferedOutputStreamTest.java

Author: pyang
Date: Thu Apr 12 02:50:40 2007
New Revision: 527865

URL: http://svn.apache.org/viewvc?view=rev&rev=527865
Log:
Apply patch for HARMONY-1082([classlib][io]compatibility:java.io.BufferedOutputStream.write(byte[], int, int) throws ArrayIndexOutOfBoundsException while RI throws NullPointerException)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedOutputStream.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/BufferedOutputStreamTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedOutputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedOutputStream.java?view=diff&rev=527865&r1=527864&r2=527865
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedOutputStream.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedOutputStream.java Thu Apr 12 02:50:40 2007
@@ -121,14 +121,17 @@
             // K0047=buffer is null
             throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
         }
-        if (offset < 0 || offset > buffer.length - length || length < 0) {
-            // K002f=Arguments out of bounds
-            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
-        }
+        
         if (count == 0 && length >= buf.length) {
             out.write(buffer, offset, length);
             return;
         }
+        
+        if (offset < 0 || offset > buffer.length - length || length < 0) {
+            // K002f=Arguments out of bounds
+            throw new ArrayIndexOutOfBoundsException(Msg.getString("K002f")); //$NON-NLS-1$
+        }
+        
         int available = buf.length - count;
         if (length < available) {
             available = length;

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/BufferedOutputStreamTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/BufferedOutputStreamTest.java?view=diff&rev=527865&r1=527864&r2=527865
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/BufferedOutputStreamTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/BufferedOutputStreamTest.java Thu Apr 12 02:50:40 2007
@@ -251,6 +251,300 @@
 		}
 	}
 
+    /**
+     * @tests java.io.BufferedOutputStream#write(byte[], int, int)
+     */
+    public void test_write_$BII_NullStream_NullArray() throws IOException {
+        OutputStream bos = new BufferedOutputStream(null);   
+        byte[] nullByteArray = null;
+        
+        try {
+            bos.write(nullByteArray, -1, -1);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        
+        try {
+            bos.write(nullByteArray, 0, -1);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        
+        try {
+            bos.write(nullByteArray, 1, -1);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            bos.write(nullByteArray, -1, 0);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            bos.write(nullByteArray, 0, 0);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        
+        try {
+            bos.write(nullByteArray, 1, 0);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        
+        try {
+            bos.write(nullByteArray, -1, 1);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+       
+        try {
+            bos.write(nullByteArray, 0, 1);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        
+        try {
+            bos.write(nullByteArray, 1, 1);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+    }
+    
+    /**
+     * @tests java.io.BufferedOutputStream#write(byte[], int, int)
+     */
+    public void test_write_$BII_NullStream_NullArray_Size() throws IOException {
+        OutputStream bos = new BufferedOutputStream(null, 1);   
+        byte[] nullByteArray = null;
+        
+        try {
+            bos.write(nullByteArray, -1, -1);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            bos.write(nullByteArray, 0, -1);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        
+        try {
+            bos.write(nullByteArray, 1, -1);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            bos.write(nullByteArray, -1, 0);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+
+        try {
+            bos.write(nullByteArray, 0, 0);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        
+        try {
+            bos.write(nullByteArray, 1, 0);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        
+        try {
+            bos.write(nullByteArray, -1, 1);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        
+        try {
+            bos.write(nullByteArray, 0, 1);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        
+        try {
+            bos.write(nullByteArray, 1, 1);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+    }
+    
+    /**
+     * @tests java.io.BufferedOutputStream#write(byte[], int, int)
+     */
+    public void test_write_$BII_NullStream() throws IOException {
+        BufferedOutputStream bos = new BufferedOutputStream(null);   
+        byte[] byteArray = new byte[10];
+        
+        try {
+            bos.write(byteArray, -1, -1);
+            fail("should throw ArrayIndexOutOfBoundsException");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            bos.write(byteArray, 0, -1);
+            fail("should throw ArrayIndexOutOfBoundsException");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // expected
+        }
+        
+        try {
+            bos.write(byteArray, 1, -1);
+            fail("should throw ArrayIndexOutOfBoundsException");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // expected
+        }
+        
+        try {
+            bos.write(byteArray, -1, 0);
+            fail("should throw ArrayIndexOutOfBoundsException");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // expected
+        }
+        
+        bos.write(byteArray, 0, 0);
+        
+        bos.write(byteArray, 1, 0);
+        
+        bos.write(byteArray, byteArray.length, 0);
+        
+        try {
+            bos.write(byteArray, byteArray.length + 1, 0);
+            fail("should throw ArrayIndexOutOfBoundsException");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            //expected
+        }
+        
+        try {
+            bos.write(byteArray, -1, 1);
+            fail("should throw ArrayIndexOutOfBoundsException");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // expected
+        }
+        
+        bos.write(byteArray, 0, 1);
+        bos.write(byteArray, 1, 1);
+        
+        bos.write(byteArray, 0, byteArray.length);
+    
+        try {
+            bos.write(byteArray, byteArray.length + 1, 1);
+            fail("should throw ArrayIndexOutOfBoundsException");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            //expected
+        }
+    }
+    
+    /**
+     * @tests java.io.BufferedOutputStream#write(byte[], int, int)
+     */
+    public void test_write_$BII_NullStream_Size() throws IOException {
+        BufferedOutputStream bos = new BufferedOutputStream(null, 1);   
+        byte[] byteArray = new byte[10];
+        
+        try {
+            bos.write(byteArray, -1, -1);
+            fail("should throw ArrayIndexOutOfBoundsException");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // expected
+        }
+
+        try {
+            bos.write(byteArray, 0, -1);
+            fail("should throw ArrayIndexOutOfBoundsException");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // expected
+        }
+        
+        try {
+            bos.write(byteArray, 1, -1);
+            fail("should throw ArrayIndexOutOfBoundsException");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // expected
+        }
+        
+        try {
+            bos.write(byteArray, -1, 0);
+            fail("should throw ArrayIndexOutOfBoundsException");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            // expected
+        }
+        
+        bos.write(byteArray, 0, 0);
+        
+        bos.write(byteArray, 1, 0);
+        
+        bos.write(byteArray, byteArray.length, 0);
+        
+        try {
+            bos.write(byteArray, byteArray.length + 1, 0);
+            fail("should throw ArrayIndexOutOfBoundsException");
+        } catch (ArrayIndexOutOfBoundsException e) {
+            //expected
+        }
+        
+        try {
+            bos.write(byteArray, -1, 1);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        
+        try {
+            bos.write(byteArray, 0, 1);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        
+        try {
+            bos.write(byteArray, 0, byteArray.length);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        
+        try {
+            bos.write(byteArray, 1, 1);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // expected
+        }
+        
+        try {
+            bos.write(byteArray, byteArray.length + 1, 1);
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            //expected
+        }
+    }
+    
 	/**
 	 * @tests java.io.BufferedOutputStream#write(int)
 	 */