Name: diC59631 Date: 05/20/98
io.LineNumberReader() does not work correctly for read().
The bottom stream of LineNumberReader() are '\r', '\n', and
when the coninued read are blocked, even if LineNumberReader#ready()
returns true after reading '\r' from the bottom stream,
LineNumberReader#read() is blocked.
Here is the repro TP. In case, represented the block of read as Error:
-------------------------
import java.io.*;
public class TP extends Reader {
int read = 0;
public static void main(String[] args) throws IOException {
Reader in = new LineNumberReader(new TP());
System.out.println("Test Start");
System.out.println("in.ready() = " + in.ready());
System.out.println("in.read() = " + in.read());
System.out.println("in.ready() = " + in.ready());
System.out.println("in.read() = " + in.read());
}
public int read(char[] b, int off, int len) {
System.out.println("read(char[" + b.length + "], " + off + ", " + len + ") = 1");
if (read == 0) {
b[off] = '\r';
} else if (read == 1) {
b[off] = '\n';
} else if (read > 1) {
throw new Error("read");
}
read++;
return 1;
}
public void close() {
throw new Error("close");
}
public boolean ready() {
System.out.println("ready() = " + (read <= 1));
return (read <= 1);
}
}
-------------------------
When compiling and ruuning (JDK1.1.5) on WinNT4.0,
the outcome is:
----------------
Test Start
ready() = true
in.ready() = true
read(char[8192], 0, 8192) = 1
in.read() = 10
ready() = true
in.ready() = true
read(char[8192], 0, 8192) = 1
read(char[8192], 0, 8192) = 1
java.lang.Error: read
at TP.read(TP.java:22)
at java.io.BufferedReader.fill(BufferedReader.java:144)
at java.io.BufferedReader.read(BufferedReader.java:161)
at java.io.LineNumberReader.read(LineNumberReader.java:91)
at TP.main(TP.java:12)
----------------
(Review ID: 30646)
======================================================================