patch: 6646588 : OutputStream.write() IndexOutOfBoundsException condition could be simplified

Dmytro Sheyko dmytro_sheyko at
Fri Jul 5 11:48:27 UTC 2013


I would like propose a patch for bug #6646588
OutputStream.write() IndexOutOfBoundsException condition could be simplified

1. Range check logic is moved from various streams/readers/writers to IndexOutOfBoundsException.
I.e. I replaced code like this
    if ((off < 0) || (off> b.length) || (len < 0) ||
            ((off + len)> b.length) || ((off + len) < 0)) {
        throw new IndexOutOfBoundsException();
with following
    IndexOutOfBoundsException.checkBounds(b, off, len);

2. Additionally in several places I replaced
    if (b == null) {
        throw new NullPointerException()
Note that for method InflaterOutputStream.write() I changed NPE message from "Null buffer for read" to more correct (in my opinion) "Null buffer for write". It seems that this message with surrounding code was just copy-pasted from

3. In PushbackReader I removed
    } catch (ArrayIndexOfBoundsException e) {
        throw new IndexOfBoundsException();
I believe this catch is unnecessary because (a) range is already checked above and System.arraycopy should not fail and (b) ArrayIndexOfBoundsException is subclass of IndexOfBoundsException, so even if AIOBE happens there is nothing wrong to let it go farther.

Thus many trivial changes are made in following packages:**

jtreg test for IndexOutOfBoundsException.checkBounds(...) is also attached.

Please review.


More information about the core-libs-dev mailing list