-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.1, 1.1.3
-
x86, sparc
-
solaris_2.5, windows_95, windows_nt
The implementation of skip() in java.io.InputStream:
public long skip(long n) throws IOException {
/* ensure that the number is a positive int */
byte data[] = new byte[(int) (n & 0xEFFFFFFF)];
return read(data);
}
First off, the bit mask above must just be a typo; it should be 0x7FFFFFFF.
As it is, it allows negative integers to be used for the array size, resulting
in a NegativeArraySizeException.
Second, since it calls read(), it could return -1 if there is EOF before any
bytes could be skipped. [Although I would argue that this is the way it
*should* be,] the JLS states that it should still return only zero in this
case (section 22.3.4).
public long skip(long n) throws IOException {
/* ensure that the number is a positive int */
byte data[] = new byte[(int) (n & 0xEFFFFFFF)];
return read(data);
}
First off, the bit mask above must just be a typo; it should be 0x7FFFFFFF.
As it is, it allows negative integers to be used for the array size, resulting
in a NegativeArraySizeException.
Second, since it calls read(), it could return -1 if there is EOF before any
bytes could be skipped. [Although I would argue that this is the way it
*should* be,] the JLS states that it should still return only zero in this
case (section 22.3.4).
- duplicates
-
JDK-4040408 java.io.InputStream.skip: Incorrect and inefficient
- Closed
-
JDK-4016710 java.io.InputStream.skip(n) works wrong with negative n
- Closed