BUG in java/io/BufferedReader.java ; patch

Henner Zeller zeller at stud.fh-heilbronn.de
Fri Jun 18 04:26:12 PDT 1999


Hi,
Just got some strange 'invalid mark' IOExceptions from BufferedReader
(latest CVS version).
It claims, that there is no mark set, though there actually _is_ a mark.

Problem is that in mark() it isn't taken care, that we've at leaset
readAheadLimit chars in the buffer. In case the size is less than
readAheadLimit, we've to fill the rest of the buffer.

This is done in the patch attached.

ciao,
  -hen
PS: keep up the good woork!
---
Henner Zeller                                 zeller at fh-heilbronn.de
 PGP pub key [77F75B39]: finger zeller at lemming.stud.fh-heilbronn.de 

 If Microsoft is the answer, it must have been a VERY silly question.
-------------- next part --------------
Index: BufferedReader.java
===================================================================
RCS file: /home/cvspublic/kaffe/libraries/javalib/java/io/BufferedReader.java,v
retrieving revision 1.5
diff -u -r1.5 BufferedReader.java
--- BufferedReader.java	1999/03/23 21:27:17	1.5
+++ BufferedReader.java	1999/06/18 11:29:09
@@ -50,6 +50,8 @@
 		// Shift data to the beginning of the buffer
 		System.arraycopy(oldbuf, pos, inbuf, 0, size - pos);
 		size -= pos;
+		if (size < readAheadLimit)
+		    refillBuffer (pos);
 		pos = 0;
 		markset = true;
 	}
@@ -159,19 +161,23 @@
 }
 
 private int refillBuffer () throws IOException {
+    // Precondition: ASSERT (!markset)
+    return refillBuffer (0);
+}
+
+private int refillBuffer (int atPos) throws IOException {
 	synchronized ( lock ) {
 		int n;
 
-		n = rd.read( inbuf, 0, inbuf.length);
-		pos = 0;
-		markset = false;
+		n = rd.read( inbuf, atPos, inbuf.length - atPos);
+		pos = atPos;
 			
 		if (n > 0) {
-			size = n;
+			size = n + atPos;
 			return (n);
 		}
 		else {
-			size = 0;
+			size = atPos;
 			return (-1);
 		}
 	}


More information about the kaffe mailing list