Name: rmT116609 Date: 05/14/2002
FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)
Windows NT Version 4.0
Build 1381 Service pack 4
DESCRIPTION OF THE PROBLEM :
If the wrapped stream of an InputStreamReader returns 0 in its read() method, InputStreamReader throws java.lang.Error. This can be confusing and difficult to isolate. It appears no such error was thrown in 1.3.0, 1.3.1_03. A more graceful handling or additional documentation explicitly stating this may prevent others from making the same mistake.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
See sample code.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.Error
at sun.nio.cs.StreamDecoder$CharsetSD.readBytes(StreamDecoder.java:417)
at sun.nio.cs.StreamDecoder$CharsetSD.implRead(StreamDecoder.java:442)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:179)
at sun.nio.cs.StreamDecoder.read0(StreamDecoder.java:129)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:172)
at java.io.InputStreamReader.read(InputStreamReader.java:167)
at Test.go(Test.java:20)
at Test.main(Test.java:6)
---------- BEGIN SOURCE ----------
import java.io.*;
public class Test {
public static void main(String args[]) throws java.io.FileNotFoundException,
java.io.IOException {
Test t=new Test(); t.go();
}
public void go() throws java.io.FileNotFoundException, java.io.IOException {
InputStream inputStream=new FileInputStream("anyfile") {
public int read(byte[] b, int off, int len) {
//...
return 0;
}
};
inputStream.read(new byte[1],0,1); //ok
InputStreamReader inputStreamr=new InputStreamReader(inputStream);
inputStreamr.read(new char[1],0,1); //error
}
}
---------- END SOURCE ----------
(Review ID: 146523)
======================================================================