8268698: Use Objects.check{Index,FromToIndex,FromIndexSize} for java.base

Reviewed-by: mchung, rriggs
This commit is contained in:
Yi Yang 2021-07-13 02:23:16 +00:00
parent a4e5f08fef
commit afe957cd97
40 changed files with 186 additions and 284 deletions

View file

@ -28,6 +28,8 @@ package sun.security.util;
import java.io.ByteArrayOutputStream;
import java.util.Arrays;
import jdk.internal.util.Preconditions;
/**
* A packed array of booleans.
*
@ -125,9 +127,7 @@ public class BitArray {
* Returns the indexed bit in this BitArray.
*/
public boolean get(int index) throws ArrayIndexOutOfBoundsException {
if (index < 0 || index >= length) {
throw new ArrayIndexOutOfBoundsException(Integer.toString(index));
}
Preconditions.checkIndex(index, length, Preconditions.AIOOBE_FORMATTER);
return (repn[subscript(index)] & position(index)) != 0;
}
@ -137,9 +137,7 @@ public class BitArray {
*/
public void set(int index, boolean value)
throws ArrayIndexOutOfBoundsException {
if (index < 0 || index >= length) {
throw new ArrayIndexOutOfBoundsException(Integer.toString(index));
}
Preconditions.checkIndex(index, length, Preconditions.AIOOBE_FORMATTER);
int idx = subscript(index);
int bit = position(index);