Hello, I would like propose a patch for bug #6646588 OutputStream.write() IndexOutOfBoundsException condition could be simplified http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6646588
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() } with Objects.requireNotNull(b); 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 DeflaterInputStream.read(). 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: java.io.* java.util.zip.* sun.** jtreg test for IndexOutOfBoundsException.checkBounds(...) is also attached. Please review. Regards, Dmytro