[K/N] Deprecate ArrayIndexOutOfBoundsException

As a part of efforts to stabilize Native stdlib.
This commit is contained in:
Abduqodiri Qurbonzoda
2023-04-09 00:48:50 +03:00
committed by Space Team
parent be87b6950c
commit 8e995e6c62
9 changed files with 365 additions and 362 deletions
@@ -10,7 +10,7 @@ import kotlin.reflect.KProperty
@Test fun forEachIndexedTest() {
val array = Array(10) { 0 }
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
array.forEachIndexed { index, _ ->
array[index + 1] = 1
}
@@ -22,20 +22,20 @@ import kotlin.reflect.KProperty
val array1 = Array(3) { 0 }
var j = 4
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices) {
array[j] = 6
j++
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices) {
array[i + 1] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices) {
array1[i] = 6
}
@@ -47,26 +47,26 @@ import kotlin.reflect.KProperty
val array1 = Array(3) { 0L }
var j = 4
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size) {
array[j] = 6
j++
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size) {
array[i - 1] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size) {
array1[i] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size + 10) {
array[i] = 6
}
@@ -78,20 +78,20 @@ import kotlin.reflect.KProperty
val array1 = Array(3) { 0L }
var j = 4
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 0) {
array[j] = 6
j++
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 0) {
array[i * 2] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 0) {
array1[i] = 6
}
@@ -101,25 +101,25 @@ import kotlin.reflect.KProperty
val b = ++a
val c = b
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in c downTo 0) {
array[i] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size + 1 downTo 0) {
array[i] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo -1) {
array[i] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size downTo 0) {
array[i] = 6
}
@@ -131,7 +131,7 @@ import kotlin.reflect.KProperty
val array1 = Array(3) { 0L }
var j = 4
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1) {
array[j] = 6
j++
@@ -140,37 +140,37 @@ import kotlin.reflect.KProperty
var length = array.size - 1
length = 2 * length
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..length) {
array[i] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1) {
array[i + 1] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1) {
array1[i] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size + 1) {
array[i] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in -1..array.size - 1) {
array[i] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size) {
array[i] = 6
}
@@ -182,38 +182,38 @@ import kotlin.reflect.KProperty
val array1 = Array(3) { 0L }
var j = 8
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1 step 2) {
array[j] = 6
j++
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1 step 2) {
array[i - 1] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size - 1 step 2) {
array1[i] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size + 1 step 2) {
array[i] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in -1..array.size - 1 step 2) {
array[i] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..array.size step 2) {
array[i] = 6
}
@@ -225,32 +225,32 @@ import kotlin.reflect.KProperty
val array1 = CharArray(3) { '0' }
var j = 8
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size step 2) {
array[j] = '6'
j++
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size step 2) {
array[i + 3] = '6'
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until array.size step 2) {
array1[i] = '6'
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0 until (array.size/0.5).toInt() step 2) {
array[i] = '6'
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in -array.size until array.size step 2) {
array[i] = '6'
}
@@ -262,38 +262,38 @@ import kotlin.reflect.KProperty
val array1 = UIntArray(3) { 0U }
var j = 8
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 0 step 2) {
array[j] = 6U
j++
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 1 step 2) {
array[i + 1] = 6U
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo 1 step 2) {
array1[i] = 6U
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in (array.size / 0.2).toInt() downTo 1 step 2) {
array[i] = 6U
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size - 1 downTo -3 step 2) {
array[i] = 6U
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.size downTo 1 step 2) {
array[i] = 6U
}
@@ -305,20 +305,20 @@ import kotlin.reflect.KProperty
val array1 = Array(3) { 0L }
var j = 8
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices step 2) {
array[j] = 6
j++
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices step 2) {
array[i - 1] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in array.indices step 2) {
array1[i] = 6
}
@@ -330,32 +330,32 @@ import kotlin.reflect.KProperty
val array1 = Array(3) { 0 }
var j = 8
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for ((index, value) in array.withIndex()) {
array[j] = 6
j++
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for ((index, value) in array.withIndex()) {
array[index + 1] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for ((index, value) in array.withIndex()) {
array[value] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for ((i, v) in (0..array.size + 30 step 2).withIndex()) {
array[i] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for ((i, v) in (0..array.size).withIndex()) {
array[v] = 8
}
@@ -367,26 +367,26 @@ import kotlin.reflect.KProperty
val array1 = Array(3) { 0 }
var j = 8
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in (0..array.size-1).reversed()) {
array[j] = 6
j++
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in (0 until array.size).reversed()) {
array1[i] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in (0..array.size).reversed()) {
array[i] = 6
}
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in (array.size downTo 0).reversed()) {
array[i] = 6
}
@@ -511,7 +511,7 @@ class Child : Base() {
@Test fun withGetter() {
val obj = WithGetter()
needSmallArray = false
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..obj.array.size-1) {
needSmallArray = true
obj.array[i] = 6
@@ -523,7 +523,7 @@ class Child : Base() {
@Test fun delegatedProperty() {
val obj = WithDelegates()
needSmallArray = false
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..obj.array.size-1) {
needSmallArray = true
obj.array[i] = 6
@@ -536,7 +536,7 @@ class Child : Base() {
val obj = Child()
val base = Base()
needSmallArray = false
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..obj.array.size-1) {
needSmallArray = true
obj.array[i] = 6
@@ -545,7 +545,7 @@ class Child : Base() {
}
needSmallArray = false
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..obj.array1.size-1) {
needSmallArray = true
obj.array1[i] = 6
@@ -554,7 +554,7 @@ class Child : Base() {
}
needSmallArray = false
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..obj.array.size-1) {
needSmallArray = true
base.array[i] = 6
@@ -569,7 +569,7 @@ val array: Array<Int> = arrayOf(1)
@Test fun customeGetter() {
val a = array
needSmallArray = false
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (index in 0 until array.size) {
a[index] = 6
}
@@ -592,7 +592,7 @@ class Third(initArray: Array<Int>) {
val a = Third(arrayOf(1, 2, 3, 4, 5))
val b = Third(arrayOf(1, 2))
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (i in 0..a.second.first.array.size-1) {
b.second.first.array[i] = 6
}
@@ -614,7 +614,7 @@ class Bar {
@Test fun differentArrays() {
val bar = Bar()
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
for (index in 0 until bar.largeArray.size) {
bar.smallArray[index] = 6
}
@@ -54,7 +54,7 @@ fun f() = 5
assertEquals(20, varargGetter(2, 2, 3, 4))
assertEquals(20, varargGetter(2, 2, 3, 4))
if (Platform.osFamily != OsFamily.WASM) {
assertFailsWith<ArrayIndexOutOfBoundsException> { varargGetter(3, 2, 3, 4) }
assertFailsWith<IndexOutOfBoundsException> { varargGetter(3, 2, 3, 4) }
}
}
}
@@ -11,16 +11,16 @@ import kotlinx.cinterop.*
arr.usePinned {
assertEquals(0, it.addressOf(0).pointed.value)
assertEquals(0, it.addressOf(9).pointed.value)
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(10)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(-1)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MAX_VALUE)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MIN_VALUE)
}
}
@@ -31,16 +31,16 @@ import kotlinx.cinterop.*
str.usePinned {
it.addressOf(0)
it.addressOf(9)
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(10)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(-1)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MAX_VALUE)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MIN_VALUE)
}
}
@@ -51,16 +51,16 @@ import kotlinx.cinterop.*
arr.usePinned {
it.addressOf(0)
it.addressOf(9)
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(10)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(-1)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MAX_VALUE)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MIN_VALUE)
}
}
@@ -71,16 +71,16 @@ import kotlinx.cinterop.*
arr.usePinned {
assertEquals(0, it.addressOf(0).pointed.value)
assertEquals(0, it.addressOf(9).pointed.value)
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(10)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(-1)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MAX_VALUE)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MIN_VALUE)
}
}
@@ -91,16 +91,16 @@ import kotlinx.cinterop.*
arr.usePinned {
assertEquals(0, it.addressOf(0).pointed.value)
assertEquals(0, it.addressOf(9).pointed.value)
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(10)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(-1)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MAX_VALUE)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MIN_VALUE)
}
}
@@ -111,16 +111,16 @@ import kotlinx.cinterop.*
arr.usePinned {
assertEquals(0, it.addressOf(0).pointed.value)
assertEquals(0, it.addressOf(9).pointed.value)
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(10)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(-1)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MAX_VALUE)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MIN_VALUE)
}
}
@@ -131,16 +131,16 @@ import kotlinx.cinterop.*
arr.usePinned {
assertEquals(0U, it.addressOf(0).pointed.value)
assertEquals(0U, it.addressOf(9).pointed.value)
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(10)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(-1)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MAX_VALUE)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MIN_VALUE)
}
}
@@ -151,16 +151,16 @@ import kotlinx.cinterop.*
arr.usePinned {
assertEquals(0U, it.addressOf(0).pointed.value)
assertEquals(0U, it.addressOf(9).pointed.value)
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(10)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(-1)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MAX_VALUE)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MIN_VALUE)
}
}
@@ -171,16 +171,16 @@ import kotlinx.cinterop.*
arr.usePinned {
assertEquals(0U, it.addressOf(0).pointed.value)
assertEquals(0U, it.addressOf(9).pointed.value)
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(10)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(-1)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MAX_VALUE)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MIN_VALUE)
}
}
@@ -191,16 +191,16 @@ import kotlinx.cinterop.*
arr.usePinned {
assertEquals(0U, it.addressOf(0).pointed.value)
assertEquals(0U, it.addressOf(9).pointed.value)
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(10)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(-1)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MAX_VALUE)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MIN_VALUE)
}
}
@@ -211,16 +211,16 @@ import kotlinx.cinterop.*
arr.usePinned {
assertEquals(0.0f, it.addressOf(0).pointed.value)
assertEquals(0.0f, it.addressOf(9).pointed.value)
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(10)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(-1)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MAX_VALUE)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MIN_VALUE)
}
}
@@ -231,16 +231,16 @@ import kotlinx.cinterop.*
arr.usePinned {
assertEquals(0.0, it.addressOf(0).pointed.value)
assertEquals(0.0, it.addressOf(9).pointed.value)
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(10)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(-1)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MAX_VALUE)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
it.addressOf(Int.MIN_VALUE)
}
}
File diff suppressed because it is too large Load Diff
@@ -13,40 +13,40 @@ import kotlin.native.concurrent.*
val array = ByteArray(17)
val results = mutableSetOf<Any>()
var counter = 0
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
results += array.getShortAt(16)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
results += array.getCharAt(22)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
results += array.getIntAt(15)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
results += array.getLongAt(14)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
results += array.getFloatAt(14)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
results += array.getDoubleAt(13)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
array.setShortAt(16, 2.toShort())
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
array.setCharAt(22, 'a')
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
array.setIntAt(15, 1234)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
array.setLongAt(14, 1.toLong())
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
array.setFloatAt(14, 1.0f)
}
assertFailsWith<ArrayIndexOutOfBoundsException> {
assertFailsWith<IndexOutOfBoundsException> {
array.setDoubleAt(13, 3.0)
}
expect(0) { results.size }
@@ -92,6 +92,8 @@ public actual open class IndexOutOfBoundsException : RuntimeException {
actual constructor(message: String?) : super(message)
}
@Deprecated("Use IndexOutOfBoundsException instead.")
@DeprecatedSinceKotlin(warningSince = "1.9")
public open class ArrayIndexOutOfBoundsException : IndexOutOfBoundsException {
constructor() : super()
@@ -9,33 +9,33 @@ import kotlin.native.internal.GCUnsafeCall
/**
* Those operations allows to extract primitive values out of the [ByteArray] byte buffers.
* Data is treated as if it was in Least-Significant-Byte first (little-endian) byte order.
* If index is outside of array boundaries - [ArrayIndexOutOfBoundsException] is thrown.
* If index is outside of array boundaries - [IndexOutOfBoundsException] is thrown.
*/
/**
* Gets [UByte] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@ExperimentalUnsignedTypes
public fun ByteArray.getUByteAt(index: Int): UByte = UByte(get(index))
/**
* Gets [Char] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@GCUnsafeCall("Kotlin_ByteArray_getCharAt")
public external fun ByteArray.getCharAt(index: Int): Char
/**
* Gets [Short] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@GCUnsafeCall("Kotlin_ByteArray_getShortAt")
public external fun ByteArray.getShortAt(index: Int): Short
/**
* Gets [UShort] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@GCUnsafeCall("Kotlin_ByteArray_getShortAt")
@ExperimentalUnsignedTypes
@@ -43,14 +43,14 @@ public external fun ByteArray.getUShortAt(index: Int): UShort
/**
* Gets [Int] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@GCUnsafeCall("Kotlin_ByteArray_getIntAt")
public external fun ByteArray.getIntAt(index: Int): Int
/**
* Gets [UInt] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@GCUnsafeCall("Kotlin_ByteArray_getIntAt")
@ExperimentalUnsignedTypes
@@ -58,14 +58,14 @@ public external fun ByteArray.getUIntAt(index: Int): UInt
/**
* Gets [Long] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@GCUnsafeCall("Kotlin_ByteArray_getLongAt")
public external fun ByteArray.getLongAt(index: Int): Long
/**
* Gets [ULong] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@GCUnsafeCall("Kotlin_ByteArray_getLongAt")
@ExperimentalUnsignedTypes
@@ -73,42 +73,42 @@ public external fun ByteArray.getULongAt(index: Int): ULong
/**
* Gets [Float] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@GCUnsafeCall("Kotlin_ByteArray_getFloatAt")
public external fun ByteArray.getFloatAt(index: Int): Float
/**
* Gets [Double] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@GCUnsafeCall("Kotlin_ByteArray_getDoubleAt")
public external fun ByteArray.getDoubleAt(index: Int): Double
/**
* Sets [UByte] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@GCUnsafeCall("Kotlin_ByteArray_set")
public external fun ByteArray.setUByteAt(index: Int, value: UByte)
/**
* Sets [Char] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@GCUnsafeCall("Kotlin_ByteArray_setCharAt")
public external fun ByteArray.setCharAt(index: Int, value: Char)
/**
* Sets [Short] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@GCUnsafeCall("Kotlin_ByteArray_setShortAt")
public external fun ByteArray.setShortAt(index: Int, value: Short)
/**
* Sets [UShort] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@GCUnsafeCall("Kotlin_ByteArray_setShortAt")
@ExperimentalUnsignedTypes
@@ -116,28 +116,28 @@ public external fun ByteArray.setUShortAt(index: Int, value: UShort)
/**
* Sets [Int] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@GCUnsafeCall("Kotlin_ByteArray_setIntAt")
public external fun ByteArray.setIntAt(index: Int, value: Int)
/**
* Sets [UInt] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@GCUnsafeCall("Kotlin_ByteArray_setIntAt")
public external fun ByteArray.setUIntAt(index: Int, value: UInt)
/**
* Sets [Long] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@GCUnsafeCall("Kotlin_ByteArray_setLongAt")
public external fun ByteArray.setLongAt(index: Int, value: Long)
/**
* Sets [ULong] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@GCUnsafeCall("Kotlin_ByteArray_setLongAt")
@ExperimentalUnsignedTypes
@@ -145,14 +145,14 @@ public external fun ByteArray.setULongAt(index: Int, value: ULong)
/**
* Sets [Float] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@GCUnsafeCall("Kotlin_ByteArray_setFloatAt")
public external fun ByteArray.setFloatAt(index: Int, value: Float)
/**
* Sets [Double] out of the [ByteArray] byte buffer at specified index [index]
* @throws ArrayIndexOutOfBoundsException if [index] is outside of array boundaries.
* @throws IndexOutOfBoundsException if [index] is outside of array boundaries.
*/
@GCUnsafeCall("Kotlin_ByteArray_setDoubleAt")
public external fun ByteArray.setDoubleAt(index: Int, value: Double)
@@ -23,6 +23,7 @@ internal fun ThrowIndexOutOfBoundsException(): Nothing {
@ExportForCppRuntime
internal fun ThrowArrayIndexOutOfBoundsException(): Nothing {
@Suppress("DEPRECATION")
throw ArrayIndexOutOfBoundsException()
}
@@ -334,7 +334,7 @@ public actual fun String(chars: CharArray): String = chars.concatToString()
@DeprecatedSinceKotlin(warningSince = "1.4", errorSince = "1.5")
public actual fun String(chars: CharArray, offset: Int, length: Int): String {
if (offset < 0 || length < 0 || offset + length > chars.size)
throw ArrayIndexOutOfBoundsException()
throw IndexOutOfBoundsException()
return unsafeStringFromCharArray(chars, offset, length)
}