harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r424902 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/BufferedReader.java test/java/tests/api/java/io/BufferedReaderTest.java
Date Mon, 24 Jul 2006 04:54:19 GMT
Author: pyang
Date: Sun Jul 23 21:54:19 2006
New Revision: 424902

URL: http://svn.apache.org/viewvc?rev=424902&view=rev
Log:
Fix for HARMONY-831 ([classlib][io] compatibility: method BufferedReader().read(new char[]
{}, 7, 0) return 0 while RI throws IndexOutOfBoundsException)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedReader.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/BufferedReaderTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedReader.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedReader.java?rev=424902&r1=424901&r2=424902&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedReader.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedReader.java
Sun Jul 23 21:54:19 2006
@@ -238,55 +238,50 @@
 			if (isOpen()) {
 				// check for null
 				int bufLen = buffer.length;
+                if(offset < 0 || length < 0 || (long)offset + (long)length > bufLen){
+                    throw new ArrayIndexOutOfBoundsException();
+                }
 				if (length == 0)
-					return 0;
-				// avoid int overflow
-				if (0 <= offset && offset <= bufLen && 0 < length
-						&& length <= bufLen - offset) {
-					int required;
-					if (pos < count) {
-						/* There are bytes available in the buffer. */
-						int copylength = count - pos >= length ? length : count
-								- pos;
-						System.arraycopy(buf, pos, buffer, offset, copylength);
-						pos += copylength;
-						if (copylength == length || !in.ready())
-							return copylength;
-						offset += copylength;
-						required = length - copylength;
-					} else
-						required = length;
+                    return 0;
+                int required;
+                if (pos < count) {
+                    /* There are bytes available in the buffer. */
+                    int copylength = count - pos >= length ? length : count
+                            - pos;
+                    System.arraycopy(buf, pos, buffer, offset, copylength);
+                    pos += copylength;
+                    if (copylength == length || !in.ready())
+                        return copylength;
+                    offset += copylength;
+                    required = length - copylength;
+                } else
+                    required = length;
 
-					while (true) {
-						int read;
-						/*
-						 * If we're not marked and the required size is greater
-						 * than the buffer, simply read the bytes directly
-						 * bypassing the buffer.
-						 */
-						if (markpos == -1 && required >= buf.length) {
-							read = in.read(buffer, offset, required);
-							if (read == -1)
-								return required == length ? -1 : length
-										- required;
-						} else {
-							if (fillbuf() == -1)
-								return required == length ? -1 : length
-										- required;
-							read = count - pos >= required ? required : count
-									- pos;
-							System.arraycopy(buf, pos, buffer, offset, read);
-							pos += read;
-						}
-						required -= read;
-						if (required == 0)
-							return length;
-						if (!in.ready())
-							return length - required;
-						offset += read;
-					}
-				}
-				throw new ArrayIndexOutOfBoundsException();
+                while (true) {
+                    int read;
+                    /*
+                     * If we're not marked and the required size is greater than
+                     * the buffer, simply read the bytes directly bypassing the
+                     * buffer.
+                     */
+                    if (markpos == -1 && required >= buf.length) {
+                        read = in.read(buffer, offset, required);
+                        if (read == -1)
+                            return required == length ? -1 : length - required;
+                    } else {
+                        if (fillbuf() == -1)
+                            return required == length ? -1 : length - required;
+                        read = count - pos >= required ? required : count - pos;
+                        System.arraycopy(buf, pos, buffer, offset, read);
+                        pos += read;
+                    }
+                    required -= read;
+                    if (required == 0)
+                        return length;
+                    if (!in.ready())
+                        return length - required;
+                    offset += read;
+                }
 			}
 			throw new IOException(org.apache.harmony.luni.util.Msg.getString("K005b")); //$NON-NLS-1$
 		}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/BufferedReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/BufferedReaderTest.java?rev=424902&r1=424901&r2=424902&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/BufferedReaderTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/BufferedReaderTest.java
Sun Jul 23 21:54:19 2006
@@ -1,4 +1,4 @@
-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.io.PipedReader;
 import java.io.Reader;
 
 import tests.support.Support_StringReader;
@@ -166,7 +167,7 @@
 	/**
 	 * @tests java.io.BufferedReader#read(char[], int, int)
 	 */
-	public void test_read$CII() {
+	public void test_read$CII() throws Exception{
 		char[] ca = new char[2];
 		BufferedReader toRet = new BufferedReader(new InputStreamReader(
 				new ByteArrayInputStream(new byte[0])));
@@ -258,6 +259,13 @@
 		} catch (IOException e) {
 			fail("Unexpected: " + e);
 		}
+        
+        //regression for HARMONY-831
+        try{
+            new BufferedReader(new PipedReader(), 9).read(new char[] {}, 7, 0);
+            fail("should throw IndexOutOfBoundsException");
+        }catch(IndexOutOfBoundsException e){
+        }
 	}
 
 	/**



Mime
View raw message