summaryrefslogtreecommitdiff
path: root/core/java/android/util/ArraySet.java
diff options
context:
space:
mode:
authorKweku Adams <kwekua@google.com>2019-04-25 16:16:34 -0700
committerKweku Adams <kwekua@google.com>2019-04-26 12:22:16 -0700
commit4be0b1acaf8f4752e5a5940b5fad0602588f4741 (patch)
tree6ba6d8ae56dbdaecbb5211c35b2d79638aee3f1f /core/java/android/util/ArraySet.java
parenta23242a492a9f0c893cd7d5a25f53983218a8d97 (diff)
Gating OutOfBoundsException on targetSdkVersion.
Apps targeting Pie or older will get the old undefined behavior. Apps targeting Q or newer will get the OutOfBoundsException. Bug: 118339123 Test: atest CtsUtilTestCases Change-Id: Ibf5467aadec4a2f76ee180e963afeaf5a8a013a2
Diffstat (limited to 'core/java/android/util/ArraySet.java')
-rw-r--r--core/java/android/util/ArraySet.java16
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);
}