diff options
| author | Kweku Adams <kwekua@google.com> | 2019-03-30 00:03:17 +0000 |
|---|---|---|
| committer | Kweku Adams <kwekua@google.com> | 2019-03-30 00:03:17 +0000 |
| commit | 025a1664abaafde21ff0262a3679a3e6aab853e7 (patch) | |
| tree | 4a0331fae4be308396b31c4eaf4c494f1b1e2342 /core/java/android/util/SparseIntArray.java | |
| parent | 91ec97056451753d6db55d310fc93fbd93c61cb3 (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/SparseIntArray.java')
| -rw-r--r-- | core/java/android/util/SparseIntArray.java | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/core/java/android/util/SparseIntArray.java b/core/java/android/util/SparseIntArray.java index 9e6bad1d9ae0..c68dc4edcfb7 100644 --- a/core/java/android/util/SparseIntArray.java +++ b/core/java/android/util/SparseIntArray.java @@ -16,14 +16,15 @@ package android.util; +import android.annotation.UnsupportedAppUsage; + import com.android.internal.util.ArrayUtils; import com.android.internal.util.GrowingArrayUtils; -import java.util.Arrays; - -import android.annotation.UnsupportedAppUsage; import libcore.util.EmptyArray; +import java.util.Arrays; + /** * SparseIntArrays map integers to integers. Unlike a normal array of integers, * there can be gaps in the indices. It is intended to be more memory efficient @@ -171,6 +172,10 @@ public class SparseIntArray implements Cloneable { * key.</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); + } return mKeys[index]; } @@ -186,6 +191,10 @@ public class SparseIntArray implements Cloneable { * associated with the largest key.</p> */ public int 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); + } return mValues[index]; } @@ -193,6 +202,10 @@ public class SparseIntArray implements Cloneable { * Directly set the value at a particular index. */ public void setValueAt(int index, int value) { + if (index >= mSize) { + // The array might be slightly bigger than mSize, in which case, indexing won't fail. + throw new ArrayIndexOutOfBoundsException(index); + } mValues[index] = value; } |
