summaryrefslogtreecommitdiff
path: root/core/java/android/util/SparseBooleanArray.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/SparseBooleanArray.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/SparseBooleanArray.java')
-rw-r--r--core/java/android/util/SparseBooleanArray.java21
1 files changed, 18 insertions, 3 deletions
diff --git a/core/java/android/util/SparseBooleanArray.java b/core/java/android/util/SparseBooleanArray.java
index 03fa1c996027..557404764aed 100644
--- a/core/java/android/util/SparseBooleanArray.java
+++ b/core/java/android/util/SparseBooleanArray.java
@@ -166,9 +166,14 @@ public class SparseBooleanArray 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);
}
@@ -185,9 +190,14 @@ public class SparseBooleanArray 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 boolean 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);
}
@@ -196,9 +206,14 @@ public class SparseBooleanArray 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, boolean 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);
}