mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 15:24:43 +02:00
8268698: Use Objects.check{Index,FromToIndex,FromIndexSize} for java.base
Reviewed-by: mchung, rriggs
This commit is contained in:
parent
a4e5f08fef
commit
afe957cd97
40 changed files with 186 additions and 284 deletions
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue