diff options
Diffstat (limited to 'core/java/android/util/SparseIntArray.java')
| -rw-r--r-- | core/java/android/util/SparseIntArray.java | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/core/java/android/util/SparseIntArray.java b/core/java/android/util/SparseIntArray.java index c68dc4edcfb7..84f92690b3cf 100644 --- a/core/java/android/util/SparseIntArray.java +++ b/core/java/android/util/SparseIntArray.java @@ -170,9 +170,14 @@ public class SparseIntArray implements Cloneable { * be in ascending order, e.g., <code>keyAt(0)</code> will return the * smallest key and <code>keyAt(size()-1)</code> will return the largest * key.</p> + * + * <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> */ public int keyAt(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); } @@ -189,9 +194,14 @@ public class SparseIntArray implements Cloneable { * <code>valueAt(0)</code> will return the value associated with the * smallest key and <code>valueAt(size()-1)</code> will return the value * associated with the largest key.</p> + * + * <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> */ public int 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); } @@ -200,9 +210,14 @@ public class SparseIntArray implements Cloneable { /** * Directly set the value at a particular 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> */ public void setValueAt(int index, int value) { - 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); } |
