K
Kord2mo ago
Taubsie

Random ArrayIndexOutOfBoundsException when getting messages

Hi, I'm sometimes getting the following stacktrace error in a function of mine:
java.lang.ArrayIndexOutOfBoundsException: Index 682 out of bounds for length 682
at java.base/java.util.LinkedHashMap.valuesToArray(LinkedHashMap.java:563)
at java.base/java.util.LinkedHashMap$LinkedValues.toArray(LinkedHashMap.java:643)
at java.base/java.util.ArrayList.<init>(ArrayList.java:181)
at dev.kord.cache.map.MapLikeCollection$Companion$from$1$values$1.invokeSuspend(MapLikeCollection.kt:83)
at dev.kord.cache.map.MapLikeCollection$Companion$from$1$values$1.invoke(MapLikeCollection.kt)
at dev.kord.cache.map.MapLikeCollection$Companion$from$1$values$1.invoke(MapLikeCollection.kt)
at kotlinx.coroutines.flow.SafeFlow.collectSafely(Builders.kt:57)
at kotlinx.coroutines.flow.AbstractFlow.collect(Flow.kt:226)
at dev.kord.cache.map.internal.Action$ValueAction$onMap$$inlined$filter$1.collect(SafeCollector.common.kt:112)
at dev.kord.cache.map.internal.ActionQuery$asFlow$lambda$1$$inlined$filter$1.collect(SafeCollector.common.kt:112)
at dev.kord.core.supplier.CacheEntitySupplier$getMessagesAfter$$inlined$map$1.collect(SafeCollector.common.kt:109)
at kotlinx.coroutines.flow.FlowKtEmittersKt$onEmpty$$inlined$unsafeFlow$1.collect(SafeCollector.common.kt:110)
at kotlinx.coroutines.flow.FlowKtReduceKt.firstOrNull(Reduce.kt:239)
at kotlinx.coroutines.flow.FlowKt.firstOrNull(Unknown Source)
java.lang.ArrayIndexOutOfBoundsException: Index 682 out of bounds for length 682
at java.base/java.util.LinkedHashMap.valuesToArray(LinkedHashMap.java:563)
at java.base/java.util.LinkedHashMap$LinkedValues.toArray(LinkedHashMap.java:643)
at java.base/java.util.ArrayList.<init>(ArrayList.java:181)
at dev.kord.cache.map.MapLikeCollection$Companion$from$1$values$1.invokeSuspend(MapLikeCollection.kt:83)
at dev.kord.cache.map.MapLikeCollection$Companion$from$1$values$1.invoke(MapLikeCollection.kt)
at dev.kord.cache.map.MapLikeCollection$Companion$from$1$values$1.invoke(MapLikeCollection.kt)
at kotlinx.coroutines.flow.SafeFlow.collectSafely(Builders.kt:57)
at kotlinx.coroutines.flow.AbstractFlow.collect(Flow.kt:226)
at dev.kord.cache.map.internal.Action$ValueAction$onMap$$inlined$filter$1.collect(SafeCollector.common.kt:112)
at dev.kord.cache.map.internal.ActionQuery$asFlow$lambda$1$$inlined$filter$1.collect(SafeCollector.common.kt:112)
at dev.kord.core.supplier.CacheEntitySupplier$getMessagesAfter$$inlined$map$1.collect(SafeCollector.common.kt:109)
at kotlinx.coroutines.flow.FlowKtEmittersKt$onEmpty$$inlined$unsafeFlow$1.collect(SafeCollector.common.kt:110)
at kotlinx.coroutines.flow.FlowKtReduceKt.firstOrNull(Reduce.kt:239)
at kotlinx.coroutines.flow.FlowKt.firstOrNull(Unknown Source)
Is there anything you guys can change about that? I looked a bit into it and it seems like that's not really an issue in Kord, but I'm not too sure
3 Replies
Taubsie
TaubsieOP2mo ago
I'm simply using val message = textChannel.messages.firstOrNull { it.author?.isSelf() == true } on textChannel: GuildMessageChannel if you guys need more examples for this stacktrace lmk - Im getting that error at random times ever since I implemented it (but it seemed like a random 1/100 chance, so I ignored it for a while)
tmpod
tmpod2mo ago
@Taubsie an off-by-one, haven't seen that yet. Which version?
Taubsie
TaubsieOP2mo ago
newest through kord extensions.. so 0.16.0

Did you find this page helpful?