Code review request "6631046: BufferedInputStream.available() reports negative int on very large inputstream"

Mandy Chung mandy.chung at oracle.com
Thu Nov 18 22:34:02 UTC 2010


  6631046: BufferedInputStream.available() reports negative int on very 
large inputstream

Webrev at:
http://cr.openjdk.java.net/~mchung/6631046/webrev.00/

InputStream.available() returns an int. For streams larger than 2GB, the 
FileInputStream.available() implementation returns Integer.MAX_VALUE 
which is a reasonable choice.

java.io.BufferedInputStream and java.io.PushbackInputStream maintain a 
buffer.  The available() method in these 2 classes returns the sum of 
the number of bytes remaining to be read in the buffer and the result of 
calling the in.available().   If in.available() returns a large number, 
the result may overflow and a negative size will be returned.  This 
fixes to handle the overflow case properly.

Thanks
Mandy



More information about the core-libs-dev mailing list