This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FYI: Patch: java.io - several reader fixes


Hi list,


I commited the attached patch to fix some Reader issues in java.io.
No new mauve regressions.


Michael
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2495
diff -u -b -B -r1.2495 ChangeLog
--- ChangeLog	27 Dec 2003 20:49:11 -0000	1.2495
+++ ChangeLog	28 Dec 2003 11:53:57 -0000
@@ -1,3 +1,16 @@
+2003-12-28  Guilhem Lavaux <guilhem@kaffe.org>
+
+	* java/io/LineNumberReader.java
+	(mark): Improved error checking.
+	(read): Likewise.
+	(skip): Likewise. Skip is now really eating the specified number of
+	characters.
+	* java/io/CharArrayReader.java (read): It should throw
+	IndexOutOfBoundsException and not ArrayIndexOutOfBoundsException (see
+	mauve).
+	* java/io/BufferedReader.java (readLine): Make readLine() really block
+	until either EOF is reached or a true error happens.
+
 2003-12-27  Michael Koch  <konqueror@gmx.de>
 
 	* gnu/java/net/protocol/http/Connection.java
Index: java/io/LineNumberReader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/LineNumberReader.java,v
retrieving revision 1.10
diff -u -b -B -r1.10 LineNumberReader.java
--- java/io/LineNumberReader.java	18 Sep 2003 06:07:09 -0000	1.10
+++ java/io/LineNumberReader.java	28 Dec 2003 11:53:57 -0000
@@ -155,6 +155,9 @@
     */
   public void mark(int readLimit) throws IOException
   {
+    if (readLimit < 0)
+      throw new IllegalArgumentException("Read-ahead limit is negative");
+
     synchronized (lock)
       {
 	// This is basically the same as BufferedReader.mark.
@@ -265,9 +268,17 @@
     * @return The actual number of chars read, or -1 if end of stream
     *
     * @exception IOException If an error occurs.
+    * @exception NullPointerException If buf is null (in any case).
+    * @exception IndexOutOfBoundsException If buffer parameters (offset and
+    * count) lies outside of the buffer capacity.
     */
   public int read(char[] buf, int offset, int count) throws IOException
   {
+    if (buf == null)
+      throw new NullPointerException();
+    if (offset + count > buf.length || offset < 0)
+      throw new IndexOutOfBoundsException();
+
     if (count <= 0)
       {
 	if (count < 0)
@@ -376,14 +387,17 @@
     */
   public long skip (long count) throws IOException
   {
-    if (count <= 0)
+    if (count < 0)
+      throw new IllegalArgumentException("skip() value is negative");
+    if (count == 0)
       return 0;
 
     int skipped;
+    char[] buf = new char[1];
     
     for (skipped = 0; skipped < count; skipped++)
       {
-        int ch = read();
+        int ch = read(buf, 0, 1);
 
         if (ch < 0)
           break;
Index: java/io/BufferedReader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/BufferedReader.java,v
retrieving revision 1.15
diff -u -b -B -r1.15 BufferedReader.java
--- java/io/BufferedReader.java	26 Dec 2003 22:10:19 -0000	1.15
+++ java/io/BufferedReader.java	28 Dec 2003 11:53:57 -0000
@@ -460,12 +460,19 @@
     boolean eof = false;
     for (;;)
       {
-	int ch = read();
-	if (ch < 0)
+	// readLine should block. So we must not return until a -1 is reached.
+	if (pos >= limit)
+	  {
+	    // here count == 0 isn't sufficient to give a failure.
+	    int count = fill();
+	    if (count < 0)
 	  {
 	    eof = true;
 	    break;
 	  }
+	    continue;
+	  }
+	int ch = buffer[pos++];
 	if (ch == '\n' || ch == '\r')
 	  {
 	    // Check here if a '\r' was the last char in the buffer; if so,
Index: java/io/CharArrayReader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/io/CharArrayReader.java,v
retrieving revision 1.7
diff -u -b -B -r1.7 CharArrayReader.java
--- java/io/CharArrayReader.java	22 Jan 2002 22:40:13 -0000	1.7
+++ java/io/CharArrayReader.java	28 Dec 2003 11:53:57 -0000
@@ -228,7 +228,7 @@
 
 	/* Don't need to check pos value, arraycopy will check it. */
 	if (off < 0 || len < 0 || off + len > b.length)
-	  throw new ArrayIndexOutOfBoundsException();
+	  throw new IndexOutOfBoundsException();
 
 	if (pos >= count)
 	  return -1;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]