Loading core/java/android/content/pm/LimitedLengthInputStream.java +1 −1 Original line number Diff line number Diff line package android.content.pm; import libcore.util.ArrayUtils; import com.android.internal.util.ArrayUtils; import java.io.FilterInputStream; import java.io.IOException; Loading core/java/android/os/FileBridge.java +2 −1 Original line number Diff line number Diff line Loading @@ -22,11 +22,12 @@ import android.system.ErrnoException; import android.system.Os; import android.util.Log; import com.android.internal.util.ArrayUtils; import libcore.io.IoBridge; import libcore.io.IoUtils; import libcore.io.Memory; import libcore.io.Streams; import libcore.util.ArrayUtils; import java.io.FileDescriptor; import java.io.IOException; Loading core/java/android/os/Parcel.java +2 −1 Original line number Diff line number Diff line Loading @@ -33,11 +33,12 @@ import android.util.SparseArray; import android.util.SparseBooleanArray; import android.util.SparseIntArray; import com.android.internal.util.ArrayUtils; import dalvik.annotation.optimization.CriticalNative; import dalvik.annotation.optimization.FastNative; import dalvik.system.VMRuntime; import libcore.util.ArrayUtils; import libcore.util.SneakyThrow; import java.io.ByteArrayInputStream; Loading core/java/com/android/internal/util/ArrayUtils.java +19 −0 Original line number Diff line number Diff line Loading @@ -733,6 +733,25 @@ public class ArrayUtils { } } /** * Throws {@link ArrayIndexOutOfBoundsException} if the range is out of bounds. * @param len length of the array. Must be non-negative * @param offset start index of the range. Must be non-negative * @param count length of the range. Must be non-negative * @throws ArrayIndexOutOfBoundsException if the range from {@code offset} with length * {@code count} is out of bounds of the array */ public static void throwsIfOutOfBounds(int len, int offset, int count) { if (len < 0) { throw new ArrayIndexOutOfBoundsException("Negative length: " + len); } if ((offset | count) < 0 || offset > len - count) { throw new ArrayIndexOutOfBoundsException( "length=" + len + "; regionStart=" + offset + "; regionLength=" + count); } } /** * Returns an array with values from {@code val} minus {@code null} values * Loading core/tests/coretests/src/com/android/internal/util/ArrayUtilsTest.java +85 −0 Original line number Diff line number Diff line Loading @@ -118,4 +118,89 @@ public class ArrayUtilsTest extends TestCase { assertEquals(3, ArrayUtils.unstableRemoveIf(collection, isNull)); assertEquals(0, collection.size()); } @SmallTest public void testThrowsIfOutOfBounds_passesWhenRangeInsideArray() { ArrayUtils.throwsIfOutOfBounds(10, 2, 6); } @SmallTest public void testThrowsIfOutOfBounds_passesWhenRangeIsWholeArray() { ArrayUtils.throwsIfOutOfBounds(10, 0, 10); } @SmallTest public void testThrowsIfOutOfBounds_passesWhenEmptyRangeAtStart() { ArrayUtils.throwsIfOutOfBounds(10, 0, 0); } @SmallTest public void testThrowsIfOutOfBounds_passesWhenEmptyRangeAtEnd() { ArrayUtils.throwsIfOutOfBounds(10, 10, 0); } @SmallTest public void testThrowsIfOutOfBounds_passesWhenEmptyArray() { ArrayUtils.throwsIfOutOfBounds(0, 0, 0); } @SmallTest public void testThrowsIfOutOfBounds_failsWhenRangeStartNegative() { try { ArrayUtils.throwsIfOutOfBounds(10, -1, 5); fail(); } catch (ArrayIndexOutOfBoundsException expected) { // expected } } @SmallTest public void testThrowsIfOutOfBounds_failsWhenCountNegative() { try { ArrayUtils.throwsIfOutOfBounds(10, 5, -1); fail(); } catch (ArrayIndexOutOfBoundsException expected) { // expected } } @SmallTest public void testThrowsIfOutOfBounds_failsWhenRangeStartTooHigh() { try { ArrayUtils.throwsIfOutOfBounds(10, 11, 0); fail(); } catch (ArrayIndexOutOfBoundsException expected) { // expected } } @SmallTest public void testThrowsIfOutOfBounds_failsWhenRangeEndTooHigh() { try { ArrayUtils.throwsIfOutOfBounds(10, 5, 6); fail(); } catch (ArrayIndexOutOfBoundsException expected) { // expected } } @SmallTest public void testThrowsIfOutOfBounds_failsWhenLengthNegative() { try { ArrayUtils.throwsIfOutOfBounds(-1, 0, 0); fail(); } catch (ArrayIndexOutOfBoundsException expected) { // expected } } @SmallTest public void testThrowsIfOutOfBounds_failsWhenOverflowRangeEndTooHigh() { try { ArrayUtils.throwsIfOutOfBounds(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); fail(); } catch (ArrayIndexOutOfBoundsException expected) { // expected } } } Loading
core/java/android/content/pm/LimitedLengthInputStream.java +1 −1 Original line number Diff line number Diff line package android.content.pm; import libcore.util.ArrayUtils; import com.android.internal.util.ArrayUtils; import java.io.FilterInputStream; import java.io.IOException; Loading
core/java/android/os/FileBridge.java +2 −1 Original line number Diff line number Diff line Loading @@ -22,11 +22,12 @@ import android.system.ErrnoException; import android.system.Os; import android.util.Log; import com.android.internal.util.ArrayUtils; import libcore.io.IoBridge; import libcore.io.IoUtils; import libcore.io.Memory; import libcore.io.Streams; import libcore.util.ArrayUtils; import java.io.FileDescriptor; import java.io.IOException; Loading
core/java/android/os/Parcel.java +2 −1 Original line number Diff line number Diff line Loading @@ -33,11 +33,12 @@ import android.util.SparseArray; import android.util.SparseBooleanArray; import android.util.SparseIntArray; import com.android.internal.util.ArrayUtils; import dalvik.annotation.optimization.CriticalNative; import dalvik.annotation.optimization.FastNative; import dalvik.system.VMRuntime; import libcore.util.ArrayUtils; import libcore.util.SneakyThrow; import java.io.ByteArrayInputStream; Loading
core/java/com/android/internal/util/ArrayUtils.java +19 −0 Original line number Diff line number Diff line Loading @@ -733,6 +733,25 @@ public class ArrayUtils { } } /** * Throws {@link ArrayIndexOutOfBoundsException} if the range is out of bounds. * @param len length of the array. Must be non-negative * @param offset start index of the range. Must be non-negative * @param count length of the range. Must be non-negative * @throws ArrayIndexOutOfBoundsException if the range from {@code offset} with length * {@code count} is out of bounds of the array */ public static void throwsIfOutOfBounds(int len, int offset, int count) { if (len < 0) { throw new ArrayIndexOutOfBoundsException("Negative length: " + len); } if ((offset | count) < 0 || offset > len - count) { throw new ArrayIndexOutOfBoundsException( "length=" + len + "; regionStart=" + offset + "; regionLength=" + count); } } /** * Returns an array with values from {@code val} minus {@code null} values * Loading
core/tests/coretests/src/com/android/internal/util/ArrayUtilsTest.java +85 −0 Original line number Diff line number Diff line Loading @@ -118,4 +118,89 @@ public class ArrayUtilsTest extends TestCase { assertEquals(3, ArrayUtils.unstableRemoveIf(collection, isNull)); assertEquals(0, collection.size()); } @SmallTest public void testThrowsIfOutOfBounds_passesWhenRangeInsideArray() { ArrayUtils.throwsIfOutOfBounds(10, 2, 6); } @SmallTest public void testThrowsIfOutOfBounds_passesWhenRangeIsWholeArray() { ArrayUtils.throwsIfOutOfBounds(10, 0, 10); } @SmallTest public void testThrowsIfOutOfBounds_passesWhenEmptyRangeAtStart() { ArrayUtils.throwsIfOutOfBounds(10, 0, 0); } @SmallTest public void testThrowsIfOutOfBounds_passesWhenEmptyRangeAtEnd() { ArrayUtils.throwsIfOutOfBounds(10, 10, 0); } @SmallTest public void testThrowsIfOutOfBounds_passesWhenEmptyArray() { ArrayUtils.throwsIfOutOfBounds(0, 0, 0); } @SmallTest public void testThrowsIfOutOfBounds_failsWhenRangeStartNegative() { try { ArrayUtils.throwsIfOutOfBounds(10, -1, 5); fail(); } catch (ArrayIndexOutOfBoundsException expected) { // expected } } @SmallTest public void testThrowsIfOutOfBounds_failsWhenCountNegative() { try { ArrayUtils.throwsIfOutOfBounds(10, 5, -1); fail(); } catch (ArrayIndexOutOfBoundsException expected) { // expected } } @SmallTest public void testThrowsIfOutOfBounds_failsWhenRangeStartTooHigh() { try { ArrayUtils.throwsIfOutOfBounds(10, 11, 0); fail(); } catch (ArrayIndexOutOfBoundsException expected) { // expected } } @SmallTest public void testThrowsIfOutOfBounds_failsWhenRangeEndTooHigh() { try { ArrayUtils.throwsIfOutOfBounds(10, 5, 6); fail(); } catch (ArrayIndexOutOfBoundsException expected) { // expected } } @SmallTest public void testThrowsIfOutOfBounds_failsWhenLengthNegative() { try { ArrayUtils.throwsIfOutOfBounds(-1, 0, 0); fail(); } catch (ArrayIndexOutOfBoundsException expected) { // expected } } @SmallTest public void testThrowsIfOutOfBounds_failsWhenOverflowRangeEndTooHigh() { try { ArrayUtils.throwsIfOutOfBounds(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); fail(); } catch (ArrayIndexOutOfBoundsException expected) { // expected } } }