harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jessewil...@apache.org
Subject svn commit: r836064 - /harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayReader.java
Date Sat, 14 Nov 2009 00:00:41 GMT
Author: jessewilson
Date: Sat Nov 14 00:00:40 2009
New Revision: 836064

URL: http://svn.apache.org/viewvc?rev=836064&view=rev
Log:
Fixing CharArrayReader to use itself as its lock, and to make the argument validations required
by the spec.

Using the buf as the lock was okay, but the RI uses the CharArrayReader itself and this seems
more natural.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayReader.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayReader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayReader.java?rev=836064&r1=836063&r2=836064&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayReader.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/CharArrayReader.java
Sat Nov 14 00:00:40 2009
@@ -54,7 +54,6 @@
      *            the char array from which to read.
      */
     public CharArrayReader(char[] buf) {
-        super(buf);
         this.buf = buf;
         this.count = buf.length;
     }
@@ -75,8 +74,13 @@
      *             {@code offset} is greater than the size of {@code buf} .
      */
     public CharArrayReader(char[] buf, int offset, int length) {
-        super(buf);
-        if (offset < 0 || offset > buf.length || length < 0) {
+        /*
+         * The spec of this constructor is broken. In defining the legal values
+         * of offset and length, it doesn't consider buffer's length. And to be
+         * compatible with the broken spec, we must also test whether
+         * (offset + length) overflows.
+         */
+        if (offset < 0 || offset > buf.length || length < 0 || offset + length <
0) {
             throw new IllegalArgumentException();
         }
         this.buf = buf;
@@ -84,7 +88,8 @@
         this.markedPos = offset;
 
         /* This is according to spec */
-        this.count = this.pos + length < buf.length ? length : buf.length;
+        int bufferLength = buf.length;
+        this.count = offset + length < bufferLength ? length : bufferLength;
     }
 
     /**



Mime
View raw message