summaryrefslogtreecommitdiff
path: root/core/java/android/util/SparseArray.java
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2019-03-06 22:08:20 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-03-06 22:08:20 +0000
commit9bef843cef28ca65996aa3a242c7cb01e708cd8d (patch)
treead82e9b9f13261606f8a0f005d609c93bb04b413 /core/java/android/util/SparseArray.java
parent317928952285a1c867912dd01cd560059cfe653c (diff)
parent17d453ea85703a5bc26c0669231be4d6f0d8bbac (diff)
Merge "Checkng upper bound in *Array classes."
Diffstat (limited to 'core/java/android/util/SparseArray.java')
-rw-r--r--core/java/android/util/SparseArray.java19
1 files changed, 18 insertions, 1 deletions
diff --git a/core/java/android/util/SparseArray.java b/core/java/android/util/SparseArray.java
index 89ea2d35fc2f..67dfb02a0b95 100644
--- a/core/java/android/util/SparseArray.java
+++ b/core/java/android/util/SparseArray.java
@@ -16,10 +16,11 @@
package android.util;
+import android.annotation.UnsupportedAppUsage;
+
import com.android.internal.util.ArrayUtils;
import com.android.internal.util.GrowingArrayUtils;
-import android.annotation.UnsupportedAppUsage;
import libcore.util.EmptyArray;
/**
@@ -171,6 +172,10 @@ public class SparseArray<E> implements Cloneable {
* the behavior is undefined.</p>
*/
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;
@@ -279,6 +284,10 @@ public class SparseArray<E> implements Cloneable {
* the behavior is undefined.</p>
*/
public int 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();
}
@@ -302,6 +311,10 @@ public class SparseArray<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();
}
@@ -317,6 +330,10 @@ public class SparseArray<E> implements Cloneable {
* <p>For indices outside of the range <code>0...size()-1</code>, the behavior is undefined.</p>
*/
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();
}