-
Bug
-
Resolution: Fixed
-
P4
-
9
-
b34
-
Not verified
OutputStream.write(byte[],int,int) has the bounds checks
if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
}
whereas InputStream.read(byte[],int,int) has
if (off < 0 || len < 0 || len > b.length - off) {
throw new IndexOutOfBoundsException();
}
which appear to subsume the checks in OS::write. The write() checks should be changed to the set used in read(). With this change, the OutputStream::write documentation
* If <code>off</code> is negative, or <code>len</code> is negative, or
* <code>off+len</code> is greater than the length of the array
* {@code b}, then an {@code IndexOutOfBoundsException} is thrown.
would no longer correspond exactly to the implementation but would not be strictly inaccurate so no change to it should be necessary.
if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
}
whereas InputStream.read(byte[],int,int) has
if (off < 0 || len < 0 || len > b.length - off) {
throw new IndexOutOfBoundsException();
}
which appear to subsume the checks in OS::write. The write() checks should be changed to the set used in read(). With this change, the OutputStream::write documentation
* If <code>off</code> is negative, or <code>len</code> is negative, or
* <code>off+len</code> is greater than the length of the array
* {@code b}, then an {@code IndexOutOfBoundsException} is thrown.
would no longer correspond exactly to the implementation but would not be strictly inaccurate so no change to it should be necessary.
- duplicates
-
JDK-6646588 OutputStream.write() IndexOutOfBoundsException condition could be simplified
- Closed
- links to