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

Crash when unfollowing hashtags in FollowedTagsActivity #3333

Closed
1 task done
connyduck opened this issue Feb 18, 2023 · 2 comments · Fixed by #3334
Closed
1 task done

Crash when unfollowing hashtags in FollowedTagsActivity #3333

connyduck opened this issue Feb 18, 2023 · 2 comments · Fixed by #3334
Assignees

Comments

@connyduck
Copy link
Collaborator

Steps to reproduce:

  • follow two hashtags
  • go to the "Followed hashtags" view
  • unfollow the first hashtag in the list
  • unfollow the second hashtag (now the only one)
  • crash
Exception java.lang.IndexOutOfBoundsException: Index: 1, Size: 1
  at java.util.ArrayList.remove (ArrayList.java:503)
  at com.keylesspalace.tusky.components.followedtags.FollowedTagsActivity$unfollow$1.invokeSuspend (FollowedTagsActivity.kt:116)
  at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith (ContinuationImpl.kt:33)
  at kotlinx.coroutines.DispatchedTask.run (DispatchedTask.kt:106)
  at android.os.Handler.handleCallback (Handler.java:907)
  at android.os.Handler.dispatchMessage (Handler.java:105)
  at android.os.Looper.loop (Looper.java:216)
  at android.app.ActivityThread.main (ActivityThread.java:7625)
  at java.lang.reflect.Method.invoke (Method.java)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:524)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:987)

  • Tusky Version: 21.0

  • Android Version: All

  • Android Device: All

  • Mastodon instance (if applicable): mastodon.social, chaos.social

  • I searched or browsed the repo’s other issues to ensure this is not a duplicate.

@Tak Tak self-assigned this Feb 18, 2023
@nikclayton
Copy link
Contributor

Looking...

@nikclayton
Copy link
Contributor

    override fun onBindViewHolder(holder: BindingHolder<ItemFollowedHashtagBinding>, position: Int) {
        viewModel.tags[position].let { tag ->
            holder.itemView.findViewById<TextView>(R.id.followed_tag).text = tag.name
            holder.itemView.findViewById<ImageButton>(R.id.followed_tag_unfollow).setOnClickListener {
                actionListener.unfollow(tag.name, position)
            }
        }
    }

in FollowedTagsAdapter binds the position at the time the item is bound, not when it's clicked. So removing the second item after the first tries the remove the second item with position == 1 instead of position == 0

@Tak Tak assigned nikclayton and unassigned Tak Feb 19, 2023
connyduck pushed a commit that referenced this issue Feb 20, 2023
…3334)

This ensures that the position is valid w.r.t. to the backing array.

Fixes #3333
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 a pull request may close this issue.

3 participants