ArrayIndexOutOfBoundsException: length=2; index=2 (Kotlin)

Writing a small program on Android using Kotlin and sometimes getting ArrayIndexOutOfBoundsException: length=2; index=2

java.lang.ArrayIndexOutOfBoundsException: length=2; index=2
at java.util.Arrays$ArrayList.get(Arrays.java:3769)
at com.example.MainActivity.Q(:271)
at com.example.MainActivity.K(:44)
at com.example.MainActivity$e.b(:173)
at com.example.MainActivity$e.a(:44)
at androidx.lifecycle.LiveData.b(:131)
at androidx.lifecycle.LiveData.c(:149)
at androidx.lifecycle.LiveData.i(:307)
at b.o.o.i(:50)
at c.a.b$d.f(:185)
at d.e.a.a.a0$c$a.run(:187)
at android.os.Handler.handleCallback(Handler.java:794)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:6662)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)

I can't reproduce the issue, but a team member experienced this bug and shared with me to resolve, so may I know the exact line number causes this exception

Line number: 173

   viewModel.peers.observe(this, {
        if (it != null) {
            handlePeers(it) // 173
        }
    })

Line number: 271

for (i in peers.indices) if (peers[i] != curPeers.getOrNull(i)) when (val peer = peers[i]) {
            is LocalPeer -> {
                peer.getVideoTracks()["camera"]?.addRenderer(viewRenderers[i]) // 271
                peerViews[i].setMirror(true)
            }
            is RemotePeer -> {
                peer.getVideoTracks()["camera"]?.addRenderer(viewRenderers[i])
                peerViews[i].setMirror(false)
            }
            else -> {

            }
        }

Line number: 307

        for (i in peerViews.indices) {
            if (i < peerViews.size) { // peers
                peerViews[i].visibility = VISIBLE
            } else {
                peerViews[i].visibility = GONE
            }
        } // 307

Line number: 149

        if (it != null) {
            binding.mainView.apply {
                init(null)
                setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT)
                setEnableHardwareScaler(false)
            }

            try {
                initSubView(it, binding.subView1)
                initSubView(it, binding.subView2)
            } catch (e: Exception) {

            }
           // 149
        }