Skip to content

Commit 1ae7833

Browse files
authored
Use the exact same invariant checks as the JDK superclass
Add missing Javadoc `@param` tag
1 parent c6d1b15 commit 1ae7833

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/main/java/org/apache/commons/io/input/QueueInputStream.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,20 +236,19 @@ public int read() {
236236
* @param length the maximum number of bytes to read.
237237
* @return the total number of bytes read into the buffer, or {@code -1} if there is no more data because the
238238
* end of the stream has been reached.
239+
* @throws NullPointerException If {@code b} is {@code null}.
239240
* @throws IllegalStateException if thread is interrupted while waiting for the first byte.
240241
* @throws IndexOutOfBoundsException if {@code offset} is negative, {@code length} is negative, or {@code length} is
241242
* greater than {@code b.length - offset}.
242243
* @since 2.20.0
243244
*/
244245
@Override
245246
public int read(final byte[] b, final int offset, final int length) {
246-
if (offset > b.length || offset < 0) {
247-
throw new IndexOutOfBoundsException("Offset out of bounds: " + offset);
248-
}
249-
if (length < 0 || length > b.length - offset) {
250-
throw new IndexOutOfBoundsException("Length out of bounds: " + length);
251-
}
252-
if (length == 0) {
247+
if (b == null) {
248+
throw new NullPointerException();
249+
} else if (offset < 0 || length < 0 || length > b.length - offset) {
250+
throw new IndexOutOfBoundsException();
251+
} else if (length == 0) {
253252
return 0;
254253
}
255254
final List<Integer> drain = new ArrayList<>(length);

0 commit comments

Comments
 (0)