I’m updating a Java codebase to Kotlin. I’m stuck on trying to update
Arrays.copyOfRange()
fun copyData(
codePointsWindow: IntArray,
pointer: Int,
dataLength: Int,
read: Int,
): IntArray {
return Arrays.copyOfRange(codePointsWindow, pointer, dataLength + read)
}
IntelliJ pops-up a warning, “Should be replaced with Kotlin function”, and provides a quickfix:
return codePointsWindow.copyOfRange(pointer, dataLength + read)
However then a lot of tests fail with
toIndex (11) is greater than size (0).
java.lang.IndexOutOfBoundsException: toIndex (11) is greater than size (0).
at kotlin.collections.ArraysKt__ArraysJVMKt.copyOfRangeToIndexCheck(ArraysJVM.kt:49)
at kotlin.collections.ArraysKt___ArraysJvmKt.copyOfRange(_ArraysJvm.kt:1859)
I’ve made an issue
IDEA-320926 for the quickfix not producing equivalent code, but can someone help me with a suitable replacement for now?