harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r375584 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/BufferedReader.java test/java/org/apache/harmony/tests/java/io/AllTests.java test/java/org/apache/harmony/tests/java/io/BufferedReaderTest.java
Date Tue, 07 Feb 2006 12:13:57 GMT
Author: tellison
Date: Tue Feb  7 04:13:22 2006
New Revision: 375584

URL: http://svn.apache.org/viewcvs?rev=375584&view=rev
Log:
Fix for HARMONY-54 (java.io.BufferedReader.read(null,int off,int len) does not throw NPE when
len==0)

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/BufferedReaderTest.java
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/org/apache/harmony/tests/java/io/AllTests.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedReader.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/BufferedReader.java?rev=375584&r1=375583&r2=375584&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
Tue Feb  7 04:13:22 2006
@@ -229,11 +229,13 @@
 	public int read(char[] buffer, int offset, int length) throws IOException {
 		synchronized (lock) {
 			if (isOpen()) {
+				// check for null
+				int bufLen = buffer.length;
 				if (length == 0)
 					return 0;
 				// avoid int overflow
-				if (0 <= offset && offset <= buffer.length && 0 < length
-						&& length <= buffer.length - offset) {
+				if (0 <= offset && offset <= bufLen && 0 < length
+						&& length <= bufLen - offset) {
 					int required;
 					if (pos < count) {
 						/* There are bytes available in the buffer. */

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/AllTests.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/AllTests.java?rev=375584&r1=375583&r2=375584&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/AllTests.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/AllTests.java
Tue Feb  7 04:13:22 2006
@@ -29,6 +29,7 @@
 				"Test for org.apache.harmony.tests.java.io");
 		//$JUnit-BEGIN$
 		suite.addTestSuite(FileTest.class);
+		suite.addTestSuite(BufferedReaderTest.class);
 		suite.addTestSuite(PushBackInputStreamTest.class);
 		//$JUnit-END$
 		return suite;

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/BufferedReaderTest.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/BufferedReaderTest.java?rev=375584&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/BufferedReaderTest.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/org/apache/harmony/tests/java/io/BufferedReaderTest.java
Tue Feb  7 04:13:22 2006
@@ -0,0 +1,60 @@
+/* Copyright 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.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.tests.java.io;
+
+import java.io.BufferedReader;
+import java.io.CharArrayReader;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+public class BufferedReaderTest extends TestCase {
+
+	/**
+	 * @tests java.io.BufferedReader#read(char[], int, int)
+	 */
+	public void test_read$CII() throws IOException {
+		// Regression for HARMONY-54
+		char[] ch = {};
+		BufferedReader reader = new BufferedReader(new CharArrayReader(ch));
+		try {
+			// Check exception thrown when the reader is open.
+			reader.read(null, 1, 0);
+			fail("Assert 0: NullPointerException expected");
+		} catch (NullPointerException e) {
+			// Expected
+		}
+
+		// Now check IOException is thrown in preference to
+		// NullPointerexception when the reader is closed.
+		reader.close();
+		try {
+			reader.read(null, 1, 0);
+			fail("Assert 1: IOException expected");
+		} catch (IOException e) {
+			// Expected
+		}
+
+		try {
+			// And check that the IOException is thrown before
+			// ArrayIndexOutOfBoundException
+			reader.read(ch, 0, 42);
+			fail("Assert 2: IOException expected");
+		} catch (IOException e) {
+			// expected
+		}
+	}
+}



Mime
View raw message