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

@ -37,11 +37,6 @@ import jdk.internal.util.Preconditions;
public final class ArrayUtil {
private static final BiFunction<String, List<Number>,
ArrayIndexOutOfBoundsException> AIOOBE_SUPPLIER =
Preconditions.outOfBoundsExceptionFormatter
(ArrayIndexOutOfBoundsException::new);
public static void blockSizeCheck(int len, int blockSize) {
if ((len % blockSize) != 0) {
throw new ProviderException("Internal error in input buffering");
@ -50,7 +45,7 @@ public final class ArrayUtil {
public static void nullAndBoundsCheck(byte[] array, int offset, int len) {
// NPE is thrown when array is null
Preconditions.checkFromIndexSize(offset, len, array.length, AIOOBE_SUPPLIER);
Preconditions.checkFromIndexSize(offset, len, array.length, Preconditions.AIOOBE_FORMATTER);
}
private static void swap(byte[] arr, int i, int j) {

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);