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
|
@ -35,6 +35,7 @@ import java.io.IOException;
|
|||
import java.io.FileDescriptor;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.locks.*;
|
||||
|
@ -308,8 +309,7 @@ abstract class AsynchronousSocketChannelImpl
|
|||
{
|
||||
if (handler == null)
|
||||
throw new NullPointerException("'handler' is null");
|
||||
if ((offset < 0) || (length < 0) || (offset > dsts.length - length))
|
||||
throw new IndexOutOfBoundsException();
|
||||
Objects.checkFromIndexSize(offset, length, dsts.length);
|
||||
ByteBuffer[] bufs = Util.subsequence(dsts, offset, length);
|
||||
for (int i=0; i<bufs.length; i++) {
|
||||
if (bufs[i].isReadOnly())
|
||||
|
@ -410,8 +410,7 @@ abstract class AsynchronousSocketChannelImpl
|
|||
{
|
||||
if (handler == null)
|
||||
throw new NullPointerException("'handler' is null");
|
||||
if ((offset < 0) || (length < 0) || (offset > srcs.length - length))
|
||||
throw new IndexOutOfBoundsException();
|
||||
Objects.checkFromIndexSize(offset, length, srcs.length);
|
||||
srcs = Util.subsequence(srcs, offset, length);
|
||||
write(true, null, srcs, timeout, unit, attachment, handler);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.util.Objects;
|
|||
|
||||
import jdk.internal.access.JavaLangAccess;
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
import jdk.internal.util.Preconditions;
|
||||
import jdk.internal.vm.annotation.IntrinsicCandidate;
|
||||
|
||||
public class ISO_8859_1
|
||||
|
@ -169,24 +170,11 @@ public class ISO_8859_1
|
|||
byte[] da, int dp, int len) {
|
||||
Objects.requireNonNull(sa);
|
||||
Objects.requireNonNull(da);
|
||||
Preconditions.checkIndex(sp, sa.length, Preconditions.AIOOBE_FORMATTER);
|
||||
Preconditions.checkIndex(dp, da.length, Preconditions.AIOOBE_FORMATTER);
|
||||
|
||||
if (sp < 0 || sp >= sa.length) {
|
||||
throw new ArrayIndexOutOfBoundsException(sp);
|
||||
}
|
||||
|
||||
if (dp < 0 || dp >= da.length) {
|
||||
throw new ArrayIndexOutOfBoundsException(dp);
|
||||
}
|
||||
|
||||
int endIndexSP = sp + len - 1;
|
||||
if (endIndexSP < 0 || endIndexSP >= sa.length) {
|
||||
throw new ArrayIndexOutOfBoundsException(endIndexSP);
|
||||
}
|
||||
|
||||
int endIndexDP = dp + len - 1;
|
||||
if (endIndexDP < 0 || endIndexDP >= da.length) {
|
||||
throw new ArrayIndexOutOfBoundsException(endIndexDP);
|
||||
}
|
||||
Preconditions.checkIndex(sp + len - 1, sa.length, Preconditions.AIOOBE_FORMATTER);
|
||||
Preconditions.checkIndex(dp + len - 1, da.length, Preconditions.AIOOBE_FORMATTER);
|
||||
}
|
||||
|
||||
private CoderResult encodeArrayLoop(CharBuffer src,
|
||||
|
|
|
@ -31,6 +31,7 @@ import java.security.ProviderException;
|
|||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import jdk.internal.util.Preconditions;
|
||||
import jdk.internal.vm.annotation.IntrinsicCandidate;
|
||||
|
||||
/**
|
||||
|
@ -105,9 +106,7 @@ abstract class DigestBase extends MessageDigestSpi implements Cloneable {
|
|||
if (len == 0) {
|
||||
return;
|
||||
}
|
||||
if ((ofs < 0) || (len < 0) || (ofs > b.length - len)) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
Preconditions.checkFromIndexSize(ofs, len, b.length, Preconditions.AIOOBE_FORMATTER);
|
||||
if (bytesProcessed < 0) {
|
||||
engineReset();
|
||||
}
|
||||
|
@ -159,10 +158,7 @@ abstract class DigestBase extends MessageDigestSpi implements Cloneable {
|
|||
}
|
||||
|
||||
Objects.requireNonNull(b);
|
||||
|
||||
if (ofs < 0 || ofs >= b.length) {
|
||||
throw new ArrayIndexOutOfBoundsException(ofs);
|
||||
}
|
||||
Preconditions.checkIndex(ofs, b.length, Preconditions.AIOOBE_FORMATTER);
|
||||
|
||||
int endIndex = (limit / blockSize) * blockSize + blockSize - 1;
|
||||
if (endIndex >= b.length) {
|
||||
|
|
|
@ -32,6 +32,8 @@ import java.util.Arrays;
|
|||
import java.util.Objects;
|
||||
|
||||
import static sun.security.provider.ByteArrayAccess.*;
|
||||
|
||||
import jdk.internal.util.Preconditions;
|
||||
import jdk.internal.vm.annotation.IntrinsicCandidate;
|
||||
|
||||
/**
|
||||
|
@ -152,9 +154,7 @@ public final class MD5 extends DigestBase {
|
|||
// These checks are sufficient for the case when the method
|
||||
// 'implCompressImpl' is replaced with a compiler
|
||||
// intrinsic.
|
||||
if ((ofs < 0) || ((buf.length - ofs) < 64)) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
Preconditions.checkFromIndexSize(ofs, 64, buf.length, Preconditions.AIOOBE_FORMATTER);
|
||||
}
|
||||
|
||||
// The method 'implCompress0 seems not to use its parameters.
|
||||
|
|
|
@ -29,6 +29,8 @@ import java.util.Arrays;
|
|||
import java.util.Objects;
|
||||
|
||||
import static sun.security.provider.ByteArrayAccess.*;
|
||||
|
||||
import jdk.internal.util.Preconditions;
|
||||
import jdk.internal.vm.annotation.IntrinsicCandidate;
|
||||
|
||||
/**
|
||||
|
@ -136,9 +138,7 @@ public final class SHA extends DigestBase {
|
|||
// Checks similar to those performed by the method 'b2iBig64'
|
||||
// are sufficient for the case when the method 'implCompress0' is
|
||||
// replaced with a compiler intrinsic.
|
||||
if (ofs < 0 || (buf.length - ofs) < 64) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
Preconditions.checkFromIndexSize(ofs, 64, buf.length, Preconditions.AIOOBE_FORMATTER);
|
||||
}
|
||||
|
||||
// The method 'implCompress0 seems not to use its parameters.
|
||||
|
|
|
@ -28,6 +28,7 @@ package sun.security.provider;
|
|||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import jdk.internal.util.Preconditions;
|
||||
import jdk.internal.vm.annotation.IntrinsicCandidate;
|
||||
import static sun.security.provider.ByteArrayAccess.*;
|
||||
|
||||
|
@ -128,9 +129,7 @@ abstract class SHA2 extends DigestBase {
|
|||
// Checks similar to those performed by the method 'b2iBig64'
|
||||
// are sufficient for the case when the method 'implCompress0' is
|
||||
// replaced with a compiler intrinsic.
|
||||
if (ofs < 0 || (buf.length - ofs) < 64) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
Preconditions.checkFromIndexSize(ofs, 64, buf.length, Preconditions.AIOOBE_FORMATTER);
|
||||
}
|
||||
|
||||
// The method 'implCompressImpl' seems not to use its parameters.
|
||||
|
|
|
@ -28,6 +28,7 @@ package sun.security.provider;
|
|||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import jdk.internal.util.Preconditions;
|
||||
import jdk.internal.vm.annotation.IntrinsicCandidate;
|
||||
import static sun.security.provider.ByteArrayAccess.*;
|
||||
|
||||
|
@ -229,9 +230,7 @@ abstract class SHA5 extends DigestBase {
|
|||
// Checks similar to those performed by the method 'b2lBig128'
|
||||
// are sufficient for the case when the method 'implCompress0' is
|
||||
// replaced with a compiler intrinsic.
|
||||
if (ofs < 0 || (buf.length - ofs) < 128) {
|
||||
throw new ArrayIndexOutOfBoundsException();
|
||||
}
|
||||
Preconditions.checkFromIndexSize(ofs, 128, buf.length, Preconditions.AIOOBE_FORMATTER);
|
||||
}
|
||||
|
||||
// The method 'implCompressImpl' seems not to use its parameters.
|
||||
|
|
|
@ -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