BUG in java/io/BufferedReader.java ; patch

Henner Zeller zeller at stud.fh-heilbronn.de
Mon Jun 21 17:49:51 PDT 1999


Hi Archie,
On Mon, 21 Jun 1999, Archie Cobbs wrote:
AC| Do you have a simple test case to demonstrate this bug? I have a slightly
AC| different patch I'd like to try.

In the Attachement. Should return something like 012 / 123 / 234 / ...

I see what you mean, my patch was buggy as well: we've to refill the
Buffer at position 'size', not 'pos':
---
 if (size < readAheadLimit)
   refillBuffer (size)
---

ciao,
  -hen
---
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 --------------
/*
 * Test-case to check wether java.io.BufferedReader works.
 * H.Z.
 */
import java.io.BufferedReader;
import java.io.StringReader;

public class BufferedReaderBug {

    public static int READLEN = 3;

    public static void main (String argv[]) {
	/*
	 * the source we read from.
	 */
	StringReader source = new StringReader ("0123456789ABC");

	/*
	 * limit Buffer size to 5
	 */
	BufferedReader b = new BufferedReader (source, 5);
	char buf[] = new char [READLEN];
	
	try {
	    for (;;) {
		b.mark( READLEN );
		int charsRead = 0;
		int len = 0;
		// read until required size read ..
		while (charsRead < READLEN && 
		       (len = b.read (buf, charsRead, READLEN-charsRead)) >= 0)
		    charsRead += len;
		if (len < 0) break;   // done.
		System.err.println ("read " + buf);
		b.reset();
		b.read();    // next char
	    }
	}
	catch (java.io.IOException e) {
	    e.printStackTrace();
	}
    }
}


More information about the kaffe mailing list