summaryrefslogtreecommitdiff
path: root/core/java/android/util/ArrayMap.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/ArrayMap.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/ArrayMap.java')
-rw-r--r--core/java/android/util/ArrayMap.java21
1 files changed, 19 insertions, 2 deletions
diff --git a/core/java/android/util/ArrayMap.java b/core/java/android/util/ArrayMap.java
index 436cb4ff7072..e2af6f5ed102 100644
--- a/core/java/android/util/ArrayMap.java
+++ b/core/java/android/util/ArrayMap.java
@@ -16,12 +16,12 @@
package android.util;
-import libcore.util.EmptyArray;
-
import android.annotation.UnsupportedAppUsage;
import com.android.internal.util.ArrayUtils;
+import libcore.util.EmptyArray;
+
import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.Map;
@@ -453,6 +453,10 @@ public final class ArrayMap<K, V> implements Map<K, V> {
* @return Returns the key stored at the given index.
*/
public K 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 (K)mArray[index << 1];
}
@@ -462,6 +466,10 @@ public final class ArrayMap<K, V> implements Map<K, V> {
* @return Returns the value stored at the given index.
*/
public V 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 (V)mArray[(index << 1) + 1];
}
@@ -472,6 +480,10 @@ public final class ArrayMap<K, V> implements Map<K, V> {
* @return Returns the previous value at the given index.
*/
public V setValueAt(int index, V value) {
+ if (index >= mSize) {
+ // The array might be slightly bigger than mSize, in which case, indexing won't fail.
+ throw new ArrayIndexOutOfBoundsException(index);
+ }
index = (index << 1) + 1;
V old = (V)mArray[index];
mArray[index] = value;
@@ -665,6 +677,11 @@ public final class ArrayMap<K, V> implements Map<K, V> {
* @return Returns the value that was stored at this index.
*/
public V 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);
+ }
+
final Object old = mArray[(index << 1) + 1];
final int osize = mSize;
final int nsize;