Return-Path: Delivered-To: apmail-incubator-harmony-commits-archive@www.apache.org Received: (qmail 63320 invoked from network); 10 Aug 2006 09:06:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 10 Aug 2006 09:06:38 -0000 Received: (qmail 21664 invoked by uid 500); 10 Aug 2006 09:06:37 -0000 Delivered-To: apmail-incubator-harmony-commits-archive@incubator.apache.org Received: (qmail 21638 invoked by uid 500); 10 Aug 2006 09:06:37 -0000 Mailing-List: contact harmony-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-commits@incubator.apache.org Received: (qmail 21627 invoked by uid 99); 10 Aug 2006 09:06:37 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Aug 2006 02:06:37 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 10 Aug 2006 02:06:36 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 9BAA81A981A; Thu, 10 Aug 2006 02:06:16 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r430325 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/OutputStreamWriter.java test/java/tests/api/java/io/OutputStreamWriterTest.java Date: Thu, 10 Aug 2006 09:06:15 -0000 To: harmony-commits@incubator.apache.org From: pyang@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060810090616.9BAA81A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: pyang Date: Thu Aug 10 02:06:14 2006 New Revision: 430325 URL: http://svn.apache.org/viewvc?rev=430325&view=rev Log: Patch applied for HARMONY-1121(classlib][luni] java.io.OutputStreamWriter methods write(char[],int,int),write(int) write(String,int,int) throw wrong exceptions) 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=430325&r1=430324&r2=430325&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 Thu Aug 10 02:06:14 2006 @@ -66,7 +66,7 @@ /** * Constructs a new OutputStreamWriter using out as the - * OutputStream to write converted characters to and end as + * OutputStream to write converted characters to and enc as * the character encoding. If the encoding cannot be found, an * UnsupportedEncodingException error is thrown. * @@ -216,34 +216,34 @@ * maximum number of characters to write * * @throws IOException - * If this OuputStreamWriter has already been closed or some + * If this OutputStreamWriter has already been closed or some * other IOException occurs. * @throws IndexOutOfBoundsException - * If offset or count are outside of bounds. + * If offset or count is outside of bounds. */ public void write(char[] buf, int offset, int count) throws IOException { - if (offset < 0 || count < 0 || offset > buf.length - count) { - throw new IndexOutOfBoundsException(); + synchronized (lock) { + checkStatus(); + if (offset < 0 || offset > buf.length - count || count < 0) { + throw new IndexOutOfBoundsException(); + } + CharBuffer chars = CharBuffer.wrap(buf, offset, count); + convert(chars); } - CharBuffer chars = CharBuffer.wrap(buf, offset, count); - convert(chars); } private void convert(CharBuffer chars) throws IOException { - synchronized (lock) { - checkStatus(); - CoderResult result = encoder.encode(chars, bytes, true); - while (true) { - if (result.isError()) { - throw new IOException(result.toString()); - } else if (result.isOverflow()) { - //flush the output buffer - flush(); - result = encoder.encode(chars, bytes, true); - continue; - } - break; + CoderResult result = encoder.encode(chars, bytes, true); + while (true) { + if (result.isError()) { + throw new IOException(result.toString()); + } else if (result.isOverflow()) { + //flush the output buffer + flush(); + result = encoder.encode(chars, bytes, true); + continue; } + break; } } @@ -257,7 +257,7 @@ * the character to write * * @throws IOException - * If this OuputStreamWriter has already been closed or some + * If this OutputStreamWriter has already been closed or some * other IOException occurs. */ public void write(int oneChar) throws IOException { @@ -283,7 +283,7 @@ * maximum number of characters to write * * @throws IOException - * If this OuputStreamWriter has already been closed or some + * If this OutputStreamWriter has already been closed or some * other IOException occurs. * @throws IndexOutOfBoundsException * If count is negative @@ -291,15 +291,18 @@ * 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 (count < 0) { - throw new IndexOutOfBoundsException(); - } - if (offset > str.length() - count || offset < 0) { - throw new StringIndexOutOfBoundsException(); + synchronized (lock) { + // avoid int overflow + if (count < 0) { + throw new IndexOutOfBoundsException(); + } + if (offset > str.length() - count || offset < 0) { + throw new StringIndexOutOfBoundsException(); + } + checkStatus(); + CharBuffer chars = CharBuffer.wrap(str, offset, count + offset); + convert(chars); } - CharBuffer chars = CharBuffer.wrap(str, offset, count + offset); - convert(chars); } } 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=430325&r1=430324&r2=430325&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 Thu Aug 10 02:06:14 2006 @@ -106,6 +106,23 @@ */ public void testWritecharArrayintint() throws IOException { char[] chars = source.toCharArray(); + + //throws IndexOutOfBoundsException if offset is negative + try { + writer.write((char[]) null, -1, -1); + fail("should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + //expected + } + + //throws NullPointerException though count is negative + try { + writer.write((char[]) null, 1, -1); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + //expected + } + try { writer.write((char[]) null, 1, 1); fail(); @@ -137,6 +154,15 @@ writer.write(chars, 0, chars.length); writer.flush(); assertEquals("hi" + source, out.toString("utf-8")); + + writer.close(); + //after the stream is closed ,should throw IOException first + try { + writer.write((char[]) null, -1, -1); + fail("should throw IOException"); + } catch (IOException e) { + //expected + } } @@ -163,6 +189,17 @@ writer.flush(); str = new String(out.toByteArray(), "utf-8"); assertEquals("\u0001\u0002\uffff\uedcb", str); + + writer.close(); + //after the stream is closed ,should throw IOException + try { + writer.write(1); + fail("should throw IOException"); + } catch (IOException e) { + //expected + } + + } /* @@ -217,6 +254,37 @@ writer.write(source, 0, source.length()); writer.flush(); assertEquals("bc" + source, out.toString("utf-8")); + + writer.close(); + //throws IndexOutOfBoundsException first if count is negative + try { + writer.write((String) null, 0, -1); + fail("should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + //expected + } + + try { + writer.write((String) null, -1, 0); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + //expected + } + + try { + writer.write("abc", -1, 0); + fail("should throw StringIndexOutOfBoundsException"); + } catch (StringIndexOutOfBoundsException e) { + //expected + } + + //throws IOException + try { + writer.write("abc", 0, 1); + fail("should throw IOException"); + } catch (IOException e) { + //expected + } }