diff options
| author | TreeHugger Robot <treehugger-gerrit@google.com> | 2019-03-06 22:08:20 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-03-06 22:08:20 +0000 |
| commit | 9bef843cef28ca65996aa3a242c7cb01e708cd8d (patch) | |
| tree | ad82e9b9f13261606f8a0f005d609c93bb04b413 /core/java/android/util/SparseBooleanArray.java | |
| parent | 317928952285a1c867912dd01cd560059cfe653c (diff) | |
| parent | 17d453ea85703a5bc26c0669231be4d6f0d8bbac (diff) | |
Merge "Checkng upper bound in *Array classes."
Diffstat (limited to 'core/java/android/util/SparseBooleanArray.java')
| -rw-r--r-- | core/java/android/util/SparseBooleanArray.java | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/core/java/android/util/SparseBooleanArray.java b/core/java/android/util/SparseBooleanArray.java index d4c40954bdd1..03fa1c996027 100644 --- a/core/java/android/util/SparseBooleanArray.java +++ b/core/java/android/util/SparseBooleanArray.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; /** @@ -167,6 +168,10 @@ public class SparseBooleanArray 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]; } @@ -182,6 +187,10 @@ public class SparseBooleanArray implements Cloneable { * associated with the largest key.</p> */ public boolean 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]; } @@ -189,11 +198,19 @@ public class SparseBooleanArray implements Cloneable { * Directly set the value at a particular index. */ public void setValueAt(int index, boolean 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; } /** @hide */ public void setKeyAt(int index, int key) { + if (index >= mSize) { + // The array might be slightly bigger than mSize, in which case, indexing won't fail. + throw new ArrayIndexOutOfBoundsException(index); + } mKeys[index] = key; } |
