diff options
Diffstat (limited to 'core/java/android/util/ArrayMap.java')
| -rw-r--r-- | core/java/android/util/ArrayMap.java | 21 |
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; |
