-
Bug
-
Resolution: Fixed
-
P3
-
1.1, 1.1.5
-
1.2beta2
-
x86, sparc
-
solaris_2.5, windows_nt
-
Verified
Name: saC57035 Date: 12/03/96
The java.io.PushbackInputStream.available() method returns incorrect
number of bytes available.
Here is the test demonstrating the bug:
-----------------Test.java------------------------
import java.io.*;
public class Test {
public static void main( String argv[] ) {
PushbackInputStream in = new PushbackInputStream(
new ByteArrayInputStream(new byte[10]),5);
try {
System.out.println("Here must be 10: "+in.available());
in.read();
System.out.println("Here must be 9: "+in.available());
in.unread(20);
System.out.println("Here must be 10: "+in.available());
in.unread(20);
System.out.println("Here must be 11: "+in.available());
} catch (Throwable e) {
System.out.println("Test failed: unexpected "+e+" is thrown");
}
}
}
---------Output from the test---------------------
Here must be 10: 15
Here must be 9: 14
Here must be 10: 13
Here must be 11: 12
-------------------------------------------------
The bug is easy to fix replacing the statement in
public int available() throws IOException {
return pos + super.available();
}
with
return buf.length - pos + super.available();
That's all. Thanks.
======================================================================
- duplicates
-
JDK-4151507 PushbackInputStream.available() returns incorrect value.
-
- Closed
-