Loading... (original) (raw)

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 off is negative, or len is negative, or
* off+len 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.