-
Bug
-
Resolution: Fixed
-
P3
-
6u6
-
b120
-
x86
-
solaris_nevada
-
Verified
If you have a ByteArrayInputStream that's not positioned at offset 0, calling skip() with Long.MAX_VALUE does not move the position to the end of the stream and return the number of bytes skipped, as one would expect. This is because skip() checks whether (pos + n > count), which evaluates to false because pos+n overflows and becomes negative.
To reproduce, run the following code:
ByteArrayInputStream baos = new ByteArrayInputStream(new byte[1024]);
System.out.println("Read first byte: " + baos.read());
System.out.println("skip(): " + baos.skip(Long.MAX_VALUE));
System.out.println("Read after end of stream: " + baos.read());
Expected output:
Read first byte: 0
skip(): 1023
Read after end of stream: -1
Actual output:
Read first byte: 0
skip(): 9223372036854775807
Read after end of stream: 0
To reproduce, run the following code:
ByteArrayInputStream baos = new ByteArrayInputStream(new byte[1024]);
System.out.println("Read first byte: " + baos.read());
System.out.println("skip(): " + baos.skip(Long.MAX_VALUE));
System.out.println("Read after end of stream: " + baos.read());
Expected output:
Read first byte: 0
skip(): 1023
Read after end of stream: -1
Actual output:
Read first byte: 0
skip(): 9223372036854775807
Read after end of stream: 0