diff options
Diffstat (limited to 'core/java/android/util/ArraySet.java')
| -rw-r--r-- | core/java/android/util/ArraySet.java | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/core/java/android/util/ArraySet.java b/core/java/android/util/ArraySet.java index 4bd43d05ae61..610641d6f962 100644 --- a/core/java/android/util/ArraySet.java +++ b/core/java/android/util/ArraySet.java @@ -356,11 +356,17 @@ public final class ArraySet<E> implements Collection<E>, Set<E> { /** * Return the value at the given index in the array. + * + * <p>For indices outside of the range <code>0...size()-1</code>, the behavior is undefined for + * apps targeting {@link android.os.Build.VERSION_CODES#P} and earlier, and an + * {@link ArrayIndexOutOfBoundsException} is thrown for apps targeting + * {@link android.os.Build.VERSION_CODES#Q} and later.</p> + * * @param index The desired index, must be between 0 and {@link #size()}-1. * @return Returns the value stored at the given index. */ public E valueAt(int index) { - if (index >= mSize) { + if (index >= mSize && UtilConfig.sThrowExceptionForUpperArrayOutOfBounds) { // The array might be slightly bigger than mSize, in which case, indexing won't fail. throw new ArrayIndexOutOfBoundsException(index); } @@ -527,11 +533,17 @@ public final class ArraySet<E> implements Collection<E>, Set<E> { /** * Remove the key/value mapping at the given index. + * + * <p>For indices outside of the range <code>0...size()-1</code>, the behavior is undefined for + * apps targeting {@link android.os.Build.VERSION_CODES#P} and earlier, and an + * {@link ArrayIndexOutOfBoundsException} is thrown for apps targeting + * {@link android.os.Build.VERSION_CODES#Q} and later.</p> + * * @param index The desired index, must be between 0 and {@link #size()}-1. * @return Returns the value that was stored at this index. */ public E removeAt(int index) { - if (index >= mSize) { + if (index >= mSize && UtilConfig.sThrowExceptionForUpperArrayOutOfBounds) { // The array might be slightly bigger than mSize, in which case, indexing won't fail. throw new ArrayIndexOutOfBoundsException(index); } |
