Stop using Arrays.checkOffsetAndCount.

Start using ArrayUtils.throwsIfOutOfBounds instead. The Arrays method
is going to be removed.

Bug: 78447530
Test: cts-tradefed run cts-dev -m CtsOsTestCases (shows only unrelated failures: two user/userdebug mismatches and one from b/79471510)
Test: cts-tradefed run cts-dev -m CtsDrmTestCases
Test: adb shell am instrument -w -e class android.content.pm.LimitedLengthInputStreamTest com.android.frameworks.coretests/android.support.test.runner.AndroidJUnitRunner
Test: adb shell am instrument -w -e class android.os.FileBridgeTest com.android.frameworks.coretests/android.support.test.runner.AndroidJUnitRunner

Change-Id: Ib3cd4f4ead61dbec1ccdc94b2ad4ad9c28574582
This commit is contained in:
Pete Gillin
2018-05-10 15:40:32 +01:00
parent d0b9f983d6
commit 60f55a255f
4 changed files with 10 additions and 9 deletions

View File

@@ -1,9 +1,10 @@
package android.content.pm;
import libcore.util.ArrayUtils;
import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
/**
* A class that limits the amount of data that is read from an InputStream. When
@@ -71,7 +72,7 @@ public class LimitedLengthInputStream extends FilterInputStream {
}
final int arrayLength = buffer.length;
Arrays.checkOffsetAndCount(arrayLength, offset, byteCount);
ArrayUtils.throwsIfOutOfBounds(arrayLength, offset, byteCount);
if (mOffset > Long.MAX_VALUE - byteCount) {
throw new IOException("offset out of bounds: " + mOffset + " + " + byteCount);

View File

@@ -27,12 +27,12 @@ import libcore.io.IoBridge;
import libcore.io.IoUtils;
import libcore.io.Memory;
import libcore.io.Streams;
import libcore.util.ArrayUtils;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteOrder;
import java.util.Arrays;
/**
* Simple bridge that allows file access across process boundaries without
@@ -178,7 +178,7 @@ public class FileBridge extends Thread {
@Override
public void write(byte[] buffer, int byteOffset, int byteCount) throws IOException {
Arrays.checkOffsetAndCount(buffer.length, byteOffset, byteCount);
ArrayUtils.throwsIfOutOfBounds(buffer.length, byteOffset, byteCount);
Memory.pokeInt(mTemp, 0, CMD_WRITE, ByteOrder.BIG_ENDIAN);
Memory.pokeInt(mTemp, 4, byteCount, ByteOrder.BIG_ENDIAN);
IoBridge.write(mClient, mTemp, 0, MSG_LENGTH);

View File

@@ -31,6 +31,7 @@ import dalvik.annotation.optimization.CriticalNative;
import dalvik.annotation.optimization.FastNative;
import dalvik.system.VMRuntime;
import libcore.util.ArrayUtils;
import libcore.util.SneakyThrow;
import java.io.ByteArrayInputStream;
@@ -46,7 +47,6 @@ import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -602,7 +602,7 @@ public final class Parcel {
writeInt(-1);
return;
}
Arrays.checkOffsetAndCount(b.length, offset, len);
ArrayUtils.throwsIfOutOfBounds(b.length, offset, len);
nativeWriteByteArray(mNativePtr, b, offset, len);
}
@@ -631,7 +631,7 @@ public final class Parcel {
writeInt(-1);
return;
}
Arrays.checkOffsetAndCount(b.length, offset, len);
ArrayUtils.throwsIfOutOfBounds(b.length, offset, len);
nativeWriteBlob(mNativePtr, b, offset, len);
}

View File

@@ -27,13 +27,13 @@ import android.util.Log;
import libcore.io.IoBridge;
import libcore.io.Streams;
import libcore.util.ArrayUtils;
import java.io.FileDescriptor;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.UnknownServiceException;
import java.util.Arrays;
/**
* Stream that applies a {@link DrmManagerClient} transformation to data before
@@ -91,7 +91,7 @@ public class DrmOutputStream extends OutputStream {
@Override
public void write(byte[] buffer, int offset, int count) throws IOException {
Arrays.checkOffsetAndCount(buffer.length, offset, count);
ArrayUtils.throwsIfOutOfBounds(buffer.length, offset, count);
final byte[] exactBuffer;
if (count == buffer.length) {