commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r934035 - in /commons/proper/io/trunk/src: java/org/apache/commons/io/input/ java/org/apache/commons/io/output/ test/org/apache/commons/io/input/ test/org/apache/commons/io/output/
Date Wed, 14 Apr 2010 17:32:24 GMT
Author: jukka
Date: Wed Apr 14 17:32:23 2010
New Revision: 934035

URL: http://svn.apache.org/viewvc?rev=934035&view=rev
Log:
IO-242: Pre- and post-processing support for ProxyReader/Writer

Protect against null arguments

Modified:
    commons/proper/io/trunk/src/java/org/apache/commons/io/input/ProxyReader.java
    commons/proper/io/trunk/src/java/org/apache/commons/io/output/ProxyWriter.java
    commons/proper/io/trunk/src/test/org/apache/commons/io/input/ProxyReaderTest.java
    commons/proper/io/trunk/src/test/org/apache/commons/io/output/ProxyWriterTest.java

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/input/ProxyReader.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/input/ProxyReader.java?rev=934035&r1=934034&r2=934035&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/input/ProxyReader.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/input/ProxyReader.java Wed Apr
14 17:32:23 2010
@@ -72,7 +72,7 @@ public abstract class ProxyReader extend
     @Override
     public int read(char[] chr) throws IOException {
         try {
-            beforeRead(chr.length);
+            beforeRead(chr != null ? chr.length : 0);
             int n = in.read(chr);
             afterRead(n);
             return n;
@@ -113,7 +113,7 @@ public abstract class ProxyReader extend
     @Override
     public int read(CharBuffer target) throws IOException {
         try {
-            beforeRead(target.length());
+            beforeRead(target != null ? target.length() : 0);
             int n = in.read(target);
             afterRead(n);
             return n;

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/output/ProxyWriter.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/output/ProxyWriter.java?rev=934035&r1=934034&r2=934035&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/output/ProxyWriter.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/output/ProxyWriter.java Wed Apr
14 17:32:23 2010
@@ -93,9 +93,14 @@ public class ProxyWriter extends FilterW
     @Override
     public Writer append(CharSequence csq) throws IOException {
         try {
-            beforeWrite(csq.length());
+            int len = 0;
+            if (csq != null) {
+                len = csq.length();
+            }
+
+            beforeWrite(len);
             out.append(csq);
-            afterWrite(csq.length());
+            afterWrite(len);
         } catch (IOException e) {
             handleIOException(e);
         }
@@ -126,9 +131,14 @@ public class ProxyWriter extends FilterW
     @Override
     public void write(char[] chr) throws IOException {
         try {
-            beforeWrite(chr.length);
+            int len = 0;
+            if (chr != null) {
+                len = chr.length;
+            }
+
+            beforeWrite(len);
             out.write(chr);
-            afterWrite(chr.length);
+            afterWrite(len);
         } catch (IOException e) {
             handleIOException(e);
         }
@@ -160,9 +170,14 @@ public class ProxyWriter extends FilterW
     @Override
     public void write(String str) throws IOException {
         try {
-            beforeWrite(str.length());
+            int len = 0;
+            if (str != null) {
+                len = str.length();
+            }
+
+            beforeWrite(len);
             out.write(str);
-            afterWrite(str.length());
+            afterWrite(len);
         } catch (IOException e) {
             handleIOException(e);
         }

Modified: commons/proper/io/trunk/src/test/org/apache/commons/io/input/ProxyReaderTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/org/apache/commons/io/input/ProxyReaderTest.java?rev=934035&r1=934034&r2=934035&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/org/apache/commons/io/input/ProxyReaderTest.java (original)
+++ commons/proper/io/trunk/src/test/org/apache/commons/io/input/ProxyReaderTest.java Wed
Apr 14 17:32:23 2010
@@ -40,8 +40,6 @@ public class ProxyReaderTest extends Tes
 
         try {
             proxy.read((char[])null);
-        } catch(NullPointerException e) {
-            // Should it being throwing NPE? See IO-242
         } catch(Exception e) {
             fail("Writing null String threw " + e);
         }
@@ -60,8 +58,6 @@ public class ProxyReaderTest extends Tes
 
         try {
             proxy.read((CharBuffer)null);
-        } catch(NullPointerException e) {
-            // Should it being throwing NPE? See IO-242
         } catch(Exception e) {
             fail("Writing null String threw " + e);
         }

Modified: commons/proper/io/trunk/src/test/org/apache/commons/io/output/ProxyWriterTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/org/apache/commons/io/output/ProxyWriterTest.java?rev=934035&r1=934034&r2=934035&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/org/apache/commons/io/output/ProxyWriterTest.java (original)
+++ commons/proper/io/trunk/src/test/org/apache/commons/io/output/ProxyWriterTest.java Wed
Apr 14 17:32:23 2010
@@ -36,16 +36,12 @@ public class ProxyWriterTest extends Tes
 
         try {
             proxy.write((String)null);
-        } catch(NullPointerException e) {
-            // Should it being throwing NPE? See IO-242
         } catch(Exception e) {
             fail("Writing null String threw " + e);
         }
 
         try {
             proxy.write((String)null, 0, 0);
-        } catch(NullPointerException e) {
-            // Should it being throwing NPE? See IO-242
         } catch(Exception e) {
             fail("Writing null String threw " + e);
         }
@@ -58,16 +54,12 @@ public class ProxyWriterTest extends Tes
 
         try {
             proxy.write((char[])null);
-        } catch(NullPointerException e) {
-            // Should it being throwing NPE? See IO-242
         } catch(Exception e) {
             fail("Writing null char[] threw " + e);
         }
 
         try {
             proxy.write((char[])null, 0, 0);
-        } catch(NullPointerException e) {
-            // Should it being throwing NPE? See IO-242
         } catch(Exception e) {
             fail("Writing null char[] threw " + e);
         }



Mime
View raw message