Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent an ArrayIndexOutOfBoundsException when calling extension function LongSparseArray.values() in GoogleMap.kt #1730

Merged
merged 1 commit into from
Jun 2, 2022

Conversation

christophehenry
Copy link
Contributor

@christophehenry christophehenry commented Jun 1, 2022

Kotlin's .. operator includes the upper bound contrary to until. Including the size() value of LongSparseArray produces an ArrayIndexOutOfBoundsException. This reproduces in the current (5.0.41 (550)) version of the Tisséo (fr.tisseo.android) application. Here is the stacktrace:

06-01 14:01:00.961 E/AndroidRuntime(24926): FATAL EXCEPTION: main
06-01 14:01:00.961 E/AndroidRuntime(24926): Process: fr.tisseo.android, PID: 24926
06-01 14:01:00.961 E/AndroidRuntime(24926): java.lang.ArrayIndexOutOfBoundsException: length=126; index=126
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at androidx.collection.LongSparseArray.valueAt(LongSparseArray.java:377)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at org.microg.gms.maps.mapbox.GoogleMapKt.values(GoogleMap.kt:61)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at org.microg.gms.maps.mapbox.GoogleMapKt.access$values(GoogleMap.kt:1)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at org.microg.gms.maps.mapbox.GoogleMapImpl.applyMapType(GoogleMap.kt:347)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at org.microg.gms.maps.mapbox.GoogleMapImpl.setMapType(GoogleMap.kt:340)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at com.google.android.gms.maps.internal.IGoogleMapDelegate$Stub.onTransact(IGoogleMapDelegate.java:454)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at org.microg.gms.maps.mapbox.GoogleMapImpl.onTransact(GoogleMap.kt:808)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at android.os.Binder.transact(Binder.java:1043)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at k5.a.C(com.google.android.gms:play-services-maps@@18.0.0:2)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at p5.v.N0(com.google.android.gms:play-services-maps@@18.0.0:3)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at o5.c.n(com.google.android.gms:play-services-maps@@18.0.0:2)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at fr.tisseo.android.fragment.map.MapFragment.w2(MapFragment.kt:7)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at fr.tisseo.android.fragment.map.MapFragment.W1(MapFragment.kt:1)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at fr.tisseo.android.fragment.map.MapFragment$t.p(MapFragment.kt:1)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at fr.tisseo.android.fragment.map.MapFragment$t.u(Unknown Source:10)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at kotlinx.coroutines.flow.t$b$a.a(Collect.kt:5)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at kotlinx.coroutines.flow.i.c(Channels.kt:11)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at kotlinx.coroutines.flow.i.a(Channels.kt:1)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at kotlinx.coroutines.flow.i$a.p(Unknown Source:11)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at jb.a.h(ContinuationImpl.kt:3)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at de.v0.run(DispatchedTask.kt:22)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at de.d1.d0(EventLoop.common.kt:3)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at de.w0.e(DispatchedTask.kt:6)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at de.w0.a(DispatchedTask.kt:8)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at de.k.q(CancellableContinuationImpl.kt:2)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at de.k.E(CancellableContinuationImpl.kt:2)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at fe.a$a.t(AbstractChannel.kt:1)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at fe.d.z(ArrayChannel.kt:14)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at fe.c.o(AbstractChannel.kt:1)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at fe.g.o(Unknown Source:2)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at ge.x.a(SendingCollector.kt:1)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at kotlinx.coroutines.flow.b0.d(SharedFlow.kt:11)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at kotlinx.coroutines.flow.b0$c.p(Unknown Source:12)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at jb.a.h(ContinuationImpl.kt:3)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at de.v0.run(DispatchedTask.kt:22)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at android.os.Handler.handleCallback(Handler.java:938)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at android.os.Handler.dispatchMessage(Handler.java:99)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at android.os.Looper.loop(Looper.java:223)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at android.app.ActivityThread.main(ActivityThread.java:7664)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at java.lang.reflect.Method.invoke(Native Method)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
06-01 14:01:00.961 E/AndroidRuntime(24926): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

@@ -58,7 58,7 @@ import org.microg.gms.maps.mapbox.utils.MultiArchLoader
import org.microg.gms.maps.mapbox.utils.toGms
import org.microg.gms.maps.mapbox.utils.toMapbox

private fun <T : Any> LongSparseArray<T>.values() = (0..size()).map { valueAt(it) }.mapNotNull { it }
private fun <T : Any> LongSparseArray<T>.values() = (0 until size()).mapNotNull { valueAt(it) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.mapNotNull{ } can directly be called here, no need to remap the collection.

@christophehenry christophehenry changed the title Prevent an ArrayIndexOutOfBoundsException when calling extension function LongSparseArray.values() in GoogleMap Prevent an ArrayIndexOutOfBoundsException when calling extension function LongSparseArray.values() in GoogleMap.kt Jun 2, 2022
@mar-v-in mar-v-in merged commit 36d62fd into microg:master Jun 2, 2022
@mar-v-in
Copy link
Member

mar-v-in commented Jun 2, 2022

Thanks!

@christophehenry christophehenry deleted the fix-index-array-exception branch June 3, 2022 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants