|
Quick Lists
|
|
Bug ID:
|
4684515
|
|
Votes
|
26
|
|
Synopsis
|
InputStreamReader throws Error or loops forever if underlying stream returns 0
|
|
Category
|
java:classes_nio
|
|
Reported Against
|
1.4
, 1.2.2
|
|
Release Fixed
|
1.4.2(mantis)
|
|
State
|
10-Fix Delivered,
bug
|
|
Priority:
|
3-Medium
|
|
Related Bugs
|
4291371
,
4779065
|
|
Submit Date
|
14-MAY-2002
|
|
Description
|
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 xxxxx s 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)
======================================================================
|
|
Work Around
|
N/A
|
|
Evaluation
|
With the current 1.4.1 build, the test case provided in the description
loops forever. This is another fencepost case in the StreamDecoder logic.
-- xxxxx@xxxxx 2002/5/14
If InputStream.read returns zero, we now throw an IOException with the
following message: Underlying input stream returned zero bytes. Bug 4779065
has been filed to request clarification of the spec for InputStream.read
if no bytes are read.
-- xxxxx@xxxxx 2002-11-14
|
|
Comments
|
Submitted On 16-MAY-2002
pandaron69
Good test scaffold, very thorough!
Submitted On 16-MAY-2002
MiuA
Good Bug by milka
Submitted On 17-MAY-2002
joinhere
Sun should consider fix it.
Submitted On 02-JUL-2002
icb1000
This is a big problem when using javax.comm. If DSR is
dropped during a read it causes this crash...Please fix it!!
Submitted On 08-NOV-2002
pfhnxf0
We are currently developing a major commercial software
product and this bug is preventing us from moving to Java
1.4.1. Does anyone at Sun know if this will be fixed in the
1.4.2(Mantis release)?
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |