8276806: Use Objects.checkFromIndexSize where possible in java.base

Reviewed-by: rriggs, lancea
This commit is contained in:
Sergey Tsypanov 2021-12-02 20:00:49 +00:00 committed by Roger Riggs
parent 30087cc1b8
commit 73a9654c26
11 changed files with 40 additions and 43 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -30,6 +30,7 @@ import java.io.IOException;
import java.io.EOFException;
import java.io.PushbackInputStream;
import java.nio.charset.Charset;
import java.util.Objects;
import sun.nio.cs.UTF_8;
@ -182,9 +183,8 @@ public class ZipInputStream extends InflaterInputStream implements ZipConstants
*/
public int read(byte[] b, int off, int len) throws IOException {
ensureOpen();
if (off < 0 || len < 0 || off > b.length - len) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
Objects.checkFromIndexSize(off, len, b.length);
if (len == 0) {
return 0;
}