diff options
author | Jason Chiu <chiujason@google.com> | 2021-09-02 16:11:30 +0800 |
---|---|---|
committer | Jason Chiu <chiujason@google.com> | 2021-09-02 09:47:55 +0000 |
commit | 0f4bd41c2b1a6a1dbec2245d614d37de52a27778 (patch) | |
tree | d11dcdb09128eda5a3901c5e2e4001f29d2ac037 | |
parent | 91d4dfc7275c0bd3e96566e95f98fa934baf19b6 (diff) | |
download | robolectric-shadows-0f4bd41c2b1a6a1dbec2245d614d37de52a27778.tar.gz |
Fix the ArrayIndexOutOfBoundsException of ByteBucketArray
The framework starts to use a preserved staging-public-group for new
attributes on the new platform. The group has a bigger bucket id whose
leading bit is 1, which causes a Java signed/unsigned number problem in
multiple byte-integer conversions.
The bucket id has four bits which has a maximum number 15(0xf). However,
when the leading bit is 1, Java will auto-cast the byte to a negative
integer and cause an ArrayIndexOutOfBoundsException.
To solve this, converting the id to an unsigned integer can help Java
treat it as a positive number.
Fixes: 197494608
Bug: 196297712
Test: robotest
Change-Id: Ie5027621df2bf134ca5c5cee60c423db47f47ca7
-rw-r--r-- | resources/src/main/java/org/robolectric/res/android/ByteBucketArray.java | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/resources/src/main/java/org/robolectric/res/android/ByteBucketArray.java b/resources/src/main/java/org/robolectric/res/android/ByteBucketArray.java index 209fb1ee8..0636e1921 100644 --- a/resources/src/main/java/org/robolectric/res/android/ByteBucketArray.java +++ b/resources/src/main/java/org/robolectric/res/android/ByteBucketArray.java @@ -24,7 +24,7 @@ public abstract class ByteBucketArray<T> { } // byte bucketIndex = static_cast<byte>(index) >> 4; - byte bucketIndex = (byte) (index >> 4); + byte bucketIndex = (byte) (Byte.toUnsignedInt((byte) index) >> 4); T[] bucket = (T[]) mBuckets[bucketIndex]; if (bucket == null) { return mDefault; @@ -38,7 +38,7 @@ public abstract class ByteBucketArray<T> { // (uint32_t) index, (uint32_t) size()); // uint8_t bucketIndex = static_cast<uint8_t>(index) >> 4; - byte bucketIndex = (byte) (((byte) index) >> 4); + byte bucketIndex = (byte) (Byte.toUnsignedInt((byte) index) >> 4); Object[] bucket = mBuckets[bucketIndex]; if (bucket == null) { bucket = mBuckets[bucketIndex] = new Object[BUCKET_SIZE]; @@ -60,7 +60,7 @@ public abstract class ByteBucketArray<T> { } // editItemAt(index) = value; - byte bucketIndex = (byte) (((byte) index) >> 4); + byte bucketIndex = (byte) (Byte.toUnsignedInt((byte) index) >> 4); Object[] bucket = mBuckets[bucketIndex]; if (bucket == null) { bucket = mBuckets[bucketIndex] = new Object[BUCKET_SIZE]; |