summaryrefslogtreecommitdiff
path: root/core/java/android/util/LongSparseArray.java
diff options
context:
space:
mode:
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();
}