harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r429668 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/OutputStreamWriter.java test/java/tests/api/java/io/OutputStreamWriterTest.java
Date Tue, 08 Aug 2006 14:46:03 GMT
Author: pyang
Date: Tue Aug  8 07:46:02 2006
New Revision: 429668

URL: http://svn.apache.org/viewvc?rev=429668&view=rev
Log:
Fix for HARMONY-1092 ([classlib][luni] java.io.OutputStreamWriter.close() method does not
flush the encoder)

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

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/OutputStreamWriter.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/OutputStreamWriter.java?rev=429668&r1=429667&r2=429668&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/OutputStreamWriter.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/OutputStreamWriter.java
Tue Aug  8 07:46:02 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.
@@ -145,6 +145,7 @@
 	public void close() throws IOException {
 		synchronized (lock) {
 			if (encoder != null) {
+				encoder.flush(bytes);
 				flush();
 				out.flush();
 				out.close();
@@ -217,12 +218,12 @@
 	 * @throws IOException
 	 *             If this OuputStreamWriter has already been closed or some
 	 *             other IOException occurs.
-	 * @throws ArrayIndexOutOfBoundsException
+	 * @throws IndexOutOfBoundsException
 	 *             If offset or count are outside of bounds.
 	 */
 	public void write(char[] buf, int offset, int count) throws IOException {
-		if (offset < 0 || count < 0 || offset + count > buf.length) {
-			throw new ArrayIndexOutOfBoundsException();
+		if (offset < 0 || count < 0 || offset > buf.length - count) {
+			throw new IndexOutOfBoundsException();
 		}
 		CharBuffer chars = CharBuffer.wrap(buf, offset, count);
 		convert(chars);
@@ -284,12 +285,17 @@
 	 * @throws IOException
 	 *             If this OuputStreamWriter has already been closed or some
 	 *             other IOException occurs.
+	 * @throws IndexOutOfBoundsException    
+	 *             If count is negative    
 	 * @throws StringIndexOutOfBoundsException
-	 *             If offset or count are outside of bounds.
+	 *             If offset is negative or offset + count is outside of bounds
 	 */
 	public void write(String str, int offset, int count) throws IOException {
 		// avoid int overflow
-		if (offset < 0 || count < 0 || offset + count > str.length()) {
+		if (count < 0) {
+			throw new IndexOutOfBoundsException();
+		}
+		if (offset > str.length() - count || offset < 0) {
 			throw new StringIndexOutOfBoundsException();
 		}
 		CharBuffer chars = CharBuffer.wrap(str, offset, count + offset);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/OutputStreamWriterTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/OutputStreamWriterTest.java?rev=429668&r1=429667&r2=429668&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/OutputStreamWriterTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/OutputStreamWriterTest.java
Tue Aug  8 07:46:02 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.
@@ -194,6 +194,23 @@
 			fail();
 		} catch (StringIndexOutOfBoundsException e) {
 		}
+		
+		//throws IndexOutOfBoundsException before NullPointerException if count is negative
+		try {
+			writer.write((String) null, -1, -1);
+			fail("should throw IndexOutOfBoundsException");
+		} catch (IndexOutOfBoundsException e) {
+			//expected
+		}
+		
+		//throws NullPointerException before StringIndexOutOfBoundsException 
+		try {
+			writer.write((String) null, -1, 0);
+			fail("should throw NullPointerException");
+		} catch (NullPointerException e) {
+			//expected
+		}
+		
 		writer.write("abc", 1, 2);
 		writer.flush();
 		assertEquals("bc", out.toString("utf-8"));



Mime
View raw message