[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Update BufferedReader argument checking
From: |
Mark Wielaard |
Subject: |
[PATCH] Update BufferedReader argument checking |
Date: |
Fri, 26 Dec 2003 13:15:00 +0100 |
Hi,
The following patch imports all the trivial argument checking parts of
the changes the Guilhem made to BufferedReader for kaffe. I did not
touch the mark() and readLine() logic changed. They still have to be
checked. This just makes the diff between classpath and kaffe smaller.
2003-12-26 Guilhem Lavaux <address@hidden>
Mark Wielaard <address@hidden>
* java/io/BufferedReader.java (BufferedReader): Throw
IllegalArgumentException when size <= 0.
(mark): Document and better exception message for negative readLimit
IllegalArgumentException.
(read(char[],int,int)): Throw IndexOutOfBoundsException if offset and
count are not valid regarding buf.
(skip): Throw IllegalArgumentException when count is negative.
I'll commit this now.
Note to kaffe hackers: I made one documentation change and cleared up
one exception message. You may want to resync with classpath again and
then submit a patch for the logic changes.
Cheers,
Mark
Index: java/io/BufferedReader.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/io/BufferedReader.java,v
retrieving revision 1.19
diff -u -r1.19 BufferedReader.java
--- java/io/BufferedReader.java 11 Jun 2003 17:54:28 -0000 1.19
+++ java/io/BufferedReader.java 26 Dec 2003 12:14:04 -0000
@@ -106,10 +106,14 @@
*
* @param in The subordinate stream to read from
* @param size The buffer size to use
+ *
+ * @exception IllegalArgumentException if size <&eq; 0
*/
public BufferedReader(Reader in, int size)
{
super(in.lock);
+ if (size <= 0)
+ throw new IllegalArgumentException("Illegal buffer size: " + size);
this.in = in;
buffer = new char[size];
}
@@ -161,11 +165,12 @@
* becomes invalid
*
* @exception IOException If an error occurs
+ * @exception IllegalArgumentException if readLimit is negative.
*/
public void mark(int readLimit) throws IOException
{
if (readLimit < 0)
- throw new IllegalArgumentException();
+ throw new IllegalArgumentException("Read-ahead limit is negative");
synchronized (lock)
{
@@ -280,9 +285,14 @@
* @return The actual number of chars read, or -1 if end of stream.
*
* @exception IOException If an error occurs.
+ * @exception IndexOutOfBoundsException If offset and count are not
+ * valid regarding buf.
*/
public int read(char[] buf, int offset, int count) throws IOException
{
+ if (offset < 0 || offset + count > buf.length || count < 0)
+ throw new IndexOutOfBoundsException();
+
synchronized (lock)
{
checkStatus();
@@ -487,14 +497,17 @@
*
* @return The actual number of chars skipped.
*
- * @exception IOException If an error occurs
+ * @exception IOException If an error occurs.
+ * @exception IllegalArgumentException If count is negative.
*/
public long skip(long count) throws IOException
{
synchronized (lock)
{
checkStatus();
- if (count <= 0)
+ if (count < 0)
+ throw new IllegalArgumentException("skip value is negative");
+ if (count == 0)
return 0;
// Yet again, we need to handle the special case of a readLine
// that has a '\r' at the end of the buffer. In this case, we need
signature.asc
Description: This is a digitally signed message part
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] Update BufferedReader argument checking,
Mark Wielaard <=