Return-Path: Delivered-To: apmail-incubator-harmony-commits-archive@www.apache.org Received: (qmail 19930 invoked from network); 17 Aug 2006 13:22:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 17 Aug 2006 13:22:18 -0000 Received: (qmail 22576 invoked by uid 500); 17 Aug 2006 13:22:18 -0000 Delivered-To: apmail-incubator-harmony-commits-archive@incubator.apache.org Received: (qmail 22473 invoked by uid 500); 17 Aug 2006 13:22:18 -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 22462 invoked by uid 99); 17 Aug 2006 13:22:18 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 17 Aug 2006 06:22:18 -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, 17 Aug 2006 06:22:17 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 1A8911A981D; Thu, 17 Aug 2006 06:21:57 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r432229 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/BufferedReader.java test/java/tests/api/java/io/BufferedReaderTest.java Date: Thu, 17 Aug 2006 13:21:56 -0000 To: harmony-commits@incubator.apache.org From: hindessm@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060817132157.1A8911A981D@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: hindessm Date: Thu Aug 17 06:21:55 2006 New Revision: 432229 URL: http://svn.apache.org/viewvc?rev=432229&view=rev Log: Applied patch from "[#HARMONY-1215] [classlib][luni] java.io.BufferedReader#read(char[], int , int) method's exception order is different from RI's". 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=432229&r1=432228&r2=432229&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 Thu Aug 17 06:21:55 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. @@ -74,6 +74,8 @@ * the Reader to buffer reads on. * @param size * the size of buffer to allocate. + * @throws IllegalArgumentException + * if the size is <= 0 */ public BufferedReader(Reader in, int size) { @@ -160,6 +162,8 @@ * * @throws IOException * If an error occurs attempting mark this BufferedReader. + * @throws IllegalArgumentException + * If readlimit is < 0 */ @Override @@ -245,62 +249,58 @@ @Override public int read(char[] buffer, int offset, int length) throws IOException { synchronized (lock) { - 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; - } - 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; - } + if (!isOpen()) { + throw new IOException(Msg.getString("K005b")); //$NON-NLS-1$ + } + if (offset < 0 || offset > buffer.length - length || length < 0) { + throw new IndexOutOfBoundsException(); + } + if (length == 0) { + 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; - } + 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(Msg.getString("K005b")); //$NON-NLS-1$ } } @@ -434,6 +434,8 @@ * @throws IOException * If the BufferedReader is already closed or some other IO * error occurs. + * @throws IllegalArgumentException + * If amount is negative */ @Override 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=432229&r1=432228&r2=432229&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 Thu Aug 17 06:21:55 2006 @@ -273,6 +273,104 @@ } /** + * @tests java.io.BufferedReader#read(char[], int, int) + */ + public void test_read_$CII_Exception() throws IOException { + br = new BufferedReader(new Support_StringReader(testString)); + char[] nullCharArray = null; + char[] charArray = testString.toCharArray(); + + try { + br.read(nullCharArray, -1, -1); + fail("should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + // expected + } + + try { + br.read(nullCharArray, -1, 0); + fail("should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + // expected + } + + try { + br.read(nullCharArray, 0, -1); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + br.read(nullCharArray, 0, 0); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + br.read(nullCharArray, 0, 1); + fail("should throw NullPointerException"); + } catch (NullPointerException e) { + // expected + } + + try { + br.read(charArray, -1, -1); + fail("should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + // expected + } + + try { + br.read(charArray, -1, 0); + fail("should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + // expected + } + + br.read(charArray, 0, 0); + br.read(charArray, 0, charArray.length); + br.read(charArray, charArray.length, 0); + + try { + br.read(charArray, charArray.length + 1, 0); + fail("should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + //expected + } + + try { + br.read(charArray, charArray.length + 1, 1); + fail("should throw IndexOutOfBoundsException"); + } catch (IndexOutOfBoundsException e) { + //expected + } + + br.close(); + + try { + br.read(nullCharArray, -1, -1); + fail("should throw IOException"); + } catch (IOException e) { + // expected + } + + try { + br.read(charArray, -1, 0); + fail("should throw IOException"); + } catch (IOException e) { + // expected + } + + try { + br.read(charArray, 0, -1); + fail("should throw IOException"); + } catch (IOException e) { + // expected + } + } + /** * @tests java.io.BufferedReader#readLine() */ public void test_readLine() {