summaryrefslogtreecommitdiff
path: root/core/java/android/util/LongSparseArray.java
diff options
context:
space:
mode:
authorKweku Adams <kwekua@google.com>2019-03-30 00:03:17 +0000
committerKweku Adams <kwekua@google.com>2019-03-30 00:03:17 +0000
commit025a1664abaafde21ff0262a3679a3e6aab853e7 (patch)
tree4a0331fae4be308396b31c4eaf4c494f1b1e2342 /core/java/android/util/LongSparseArray.java
parent91ec97056451753d6db55d310fc93fbd93c61cb3 (diff)
Revert "Revert "Checkng upper bound in *Array classes.""
This reverts commit 91ec97056451753d6db55d310fc93fbd93c61cb3. Reason for revert: b/128433495 Change-Id: I4aac43f6aacd594f9c2bf58db9fbc4a1395d8888
Diffstat (limited to 'core/java/android/util/LongSparseArray.java')
-rw-r--r--core/java/android/util/LongSparseArray.java19
1 files changed, 16 insertions, 3 deletions
diff --git a/core/java/android/util/LongSparseArray.java b/core/java/android/util/LongSparseArray.java
index cf49803a7225..e4de7045721b 100644
--- a/core/java/android/util/LongSparseArray.java
+++ b/core/java/android/util/LongSparseArray.java
@@ -21,9 +21,6 @@ import com.android.internal.util.GrowingArrayUtils;
import libcore.util.EmptyArray;
-import java.util.Arrays;
-import java.util.Objects;
-
/**
* SparseArray mapping longs to Objects. Unlike a normal array of Objects,
* there can be gaps in the indices. It is intended to be more memory efficient
@@ -147,6 +144,10 @@ public class LongSparseArray<E> implements Cloneable {
* Removes the mapping at the specified index.
*/
public void removeAt(int index) {
+ if (index >= mSize) {
+ // The array might be slightly bigger than mSize, in which case, indexing won't fail.
+ throw new ArrayIndexOutOfBoundsException(index);
+ }
if (mValues[index] != DELETED) {
mValues[index] = DELETED;
mGarbage = true;
@@ -236,6 +237,10 @@ public class LongSparseArray<E> implements Cloneable {
* key.</p>
*/
public long keyAt(int index) {
+ if (index >= mSize) {
+ // The array might be slightly bigger than mSize, in which case, indexing won't fail.
+ throw new ArrayIndexOutOfBoundsException(index);
+ }
if (mGarbage) {
gc();
}
@@ -256,6 +261,10 @@ public class LongSparseArray<E> implements Cloneable {
*/
@SuppressWarnings("unchecked")
public E valueAt(int index) {
+ if (index >= mSize) {
+ // The array might be slightly bigger than mSize, in which case, indexing won't fail.
+ throw new ArrayIndexOutOfBoundsException(index);
+ }
if (mGarbage) {
gc();
}
@@ -269,6 +278,10 @@ public class LongSparseArray<E> implements Cloneable {
* LongSparseArray stores.
*/
public void setValueAt(int index, E value) {
+ if (index >= mSize) {
+ // The array might be slightly bigger than mSize, in which case, indexing won't fail.
+ throw new ArrayIndexOutOfBoundsException(index);
+ }
if (mGarbage) {
gc();
}