From 88fbf338320057a3a4991a2762f73cdc31323a0d Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Wed, 1 May 2024 18:43:45 +0200 Subject: [PATCH] fix crash when quickly unfollowing hashtags (#4404) Steps to reproduce: Quickly unfollow a bunch of hashtags, try clicking unfollow buttons multiple times. If you are faster than the network, the app crashes. ``` java.lang.ArrayIndexOutOfBoundsException: length=20; index=-1 at java.util.ArrayList.remove(ArrayList.java:506) at com.keylesspalace.tusky.components.followedtags.FollowedTagsActivity$unfollow$1.invokeSuspend(FollowedTagsActivity.kt:152) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:104) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7872) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) ``` --- .../tusky/components/followedtags/FollowedTagsActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/followedtags/FollowedTagsActivity.kt b/app/src/main/java/com/keylesspalace/tusky/components/followedtags/FollowedTagsActivity.kt index 82a17265d..e250dc989 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/followedtags/FollowedTagsActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/followedtags/FollowedTagsActivity.kt @@ -149,7 +149,7 @@ class FollowedTagsActivity : lifecycleScope.launch { api.unfollowTag(tagName).fold( { - viewModel.tags.removeAt(position) + viewModel.tags.removeIf { tag -> tag.name == tagName } Snackbar.make( this@FollowedTagsActivity, binding.followedTagsView,