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 2006/08/08 16:57:55 UTC

svn commit: r429674 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/InputStreamReader.java test/java/tests/api/java/io/InputStreamReaderTest.java

Author: pyang
Date: Tue Aug  8 07:57:55 2006
New Revision: 429674

URL: http://svn.apache.org/viewvc?rev=429674&view=rev
Log:
Fix for HARMONY-1097 ([classlib][luni] java.io.java.io.InputStreamReader#read(char[] cbuf, int offset, int length) method throws wrong exception)

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

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InputStreamReader.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InputStreamReader.java?rev=429674&r1=429673&r2=429674&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InputStreamReader.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/InputStreamReader.java Tue Aug  8 07:57:55 2006
@@ -1,4 +1,4 @@
-/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2005, 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.
@@ -369,11 +369,11 @@
 	public int read(char[] buf, int offset, int length) throws IOException {
 		synchronized (lock) {
 			if (isOpen()) {
-				if (length == 0)
-					return 0;
-				if (offset < 0 || length < 0 || offset + length > buf.length) {
+				if (offset < 0 || offset > buf.length - length || length < 0) {
 					throw new IndexOutOfBoundsException();
 				}
+				if (length == 0)
+					return 0;			
 				// read at least once
 				if (chars.limit() == chars.position()) {
 					fillBuf();

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/InputStreamReaderTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/InputStreamReaderTest.java?rev=429674&r1=429673&r2=429674&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/InputStreamReaderTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/InputStreamReaderTest.java Tue Aug  8 07:57:55 2006
@@ -1,4 +1,4 @@
-/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2005, 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.
@@ -165,6 +165,22 @@
 	 * Class under test for int read(char[], int, int)
 	 */
 	public void testReadcharArrayintint() throws IOException {
+		//throws IndexOutOfBoundsException before NullPointerException
+		try {
+			reader.read(null, -1, 1);
+			fail("Should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			//expected
+		}
+		
+		//throws NullPointerException before IndexOutOfBoundsException
+		try {
+			reader.read(null, 0, -1);
+			fail("Should throw NullPointerException");
+		} catch (NullPointerException e) {
+			//expected
+		}
+		
 		try {
 			reader.read(null, 0, 1);
 			fail();