You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2007/02/14 23:29:04 UTC

svn commit: r507720 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/PipedWriter.java test/java/tests/api/java/io/PipedWriterTest.java

Author: tellison
Date: Wed Feb 14 14:29:04 2007
New Revision: 507720

URL: http://svn.apache.org/viewvc?view=rev&rev=507720
Log:
Apply patch HARMONY-2404 ([classlib][luni] java.io.PipedWriter.write(buf,off,len) throws exeptions in different order than RI)

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

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PipedWriter.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PipedWriter.java?view=diff&rev=507720&r1=507719&r2=507720
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PipedWriter.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/PipedWriter.java Wed Feb 14 14:29:04 2007
@@ -144,20 +144,21 @@
      */
     @Override
     public void write(char buffer[], int offset, int count) throws IOException {
-        if (buffer == null) {
-            throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
-        }
-        // avoid int overflow
-        if (offset < 0 || offset > buffer.length || count < 0
-                || count > buffer.length - offset) {
-            throw new IndexOutOfBoundsException();
-        }
         synchronized (lock) {
             if (closed) {
                 throw new IOException(Msg.getString("K0078")); //$NON-NLS-1$
             }
             if (dest == null) {
                 throw new IOException(Msg.getString("K007b")); //$NON-NLS-1$
+            }
+            if (buffer == null) {
+                throw new NullPointerException(Msg.getString("K0047")); //$NON-NLS-1$
+            }
+
+            // avoid int overflow
+            if (offset < 0 || offset > buffer.length || count < 0
+                    || count > buffer.length - offset) {
+                throw new IndexOutOfBoundsException();
             }
             dest.receive(buffer, offset, count);
         }

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedWriterTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedWriterTest.java?view=diff&rev=507720&r1=507719&r2=507720
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedWriterTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/PipedWriterTest.java Wed Feb 14 14:29:04 2007
@@ -239,6 +239,55 @@
             fail("NullPointerException expected");
         } catch (NullPointerException t) {}
     }
+
+    /**
+     * @tests java.io.PipedWriter#write(char[], int, int)
+     */
+    public void test_write$CII_notConnected() throws IOException {
+        // Regression test for Harmony-2404
+        // create not connected pipe
+        PipedWriter obj = new PipedWriter();
+
+        // char array is null
+        try {
+            obj.write((char[]) null, 0, 1);
+            fail("IOException expected");
+        } catch (IOException ioe) {
+            // expected
+        }
+
+        // negative offset
+        try {
+            obj.write( new char[] { 1 }, -10, 1);
+            fail("IOException expected");
+        } catch (IOException ioe) {
+            // expected
+        }
+
+        // wrong offset
+        try {
+            obj.write( new char[] { 1 }, 10, 1);
+            fail("IOException expected");
+        } catch (IOException ioe) {
+            // expected
+        }
+
+        // negative length
+        try {
+            obj.write( new char[] { 1 }, 0, -10);
+            fail("IOException expected");
+        } catch (IOException ioe) {
+            // expected
+        }
+
+        // all valid params
+        try {
+            obj.write( new char[] { 1, 1 }, 0, 1);
+            fail("IOException expected");
+        } catch (IOException ioe) {
+            // expected
+        }
+    }
     
     /**
      * @tests java.io.PipedWriter#write(int)