From 927c63272a4d93eb250738a95503b1a8d50622d1 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 7 Jul 2023 12:37:43 +0200 Subject: [PATCH] avoid ArrayIndexOutOfBoundsException when swiping to reply. This does not fix the root cause. So probably position should not be -1 here. However if it is -1, this commit avoids the following exception and swiping to reply simply won't work. Exception java.lang.ArrayIndexOutOfBoundsException: length=163; index=-1 at java.util.ArrayList.get (ArrayList.java:439) at com.nextcloud.talk.chat.ChatActivity$setupSwipeToReply$messageSwipeController$1.showReplyUI (ChatActivity.kt:1144) at com.nextcloud.talk.ui.recyclerview.MessageSwipeCallback.setTouchListener$lambda$0 (MessageSwipeCallback.kt:137) at com.nextcloud.talk.ui.recyclerview.MessageSwipeCallback.$r8$lambda$hYMm2zsKL8yVqo4e364Wb8cWEW8 at com.nextcloud.talk.ui.recyclerview.MessageSwipeCallback$$ExternalSyntheticLambda0.onTouch at android.view.View.dispatchTouchEvent (View.java:15046) at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3115) at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2788) at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2802) at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2802) at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2802) at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2802) at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2802) at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2802) at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3121) at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2802) at com.android.internal.policy.DecorView.superDispatchTouchEvent (DecorView.java:500) at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent (PhoneWindow.java:1912) at android.app.Activity.dispatchTouchEvent (Activity.java:4299) at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent (WindowCallbackWrapper.java:70) at com.android.internal.policy.DecorView.dispatchTouchEvent (DecorView.java:458) at android.view.View.dispatchPointerEvent (View.java:15309) at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent (ViewRootImpl.java:6778) at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess (ViewRootImpl.java:6578) at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:6034) at android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:6091) at android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:6057) at android.view.ViewRootImpl$AsyncInputStage.forward (ViewRootImpl.java:6222) at android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:6065) at android.view.ViewRootImpl$AsyncInputStage.apply (ViewRootImpl.java:6279) at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:6038) at android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:6091) at android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:6057) at android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:6065) at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:6038) at android.view.ViewRootImpl.deliverInputEvent (ViewRootImpl.java:9206) at android.view.ViewRootImpl.doProcessInputEvents (ViewRootImpl.java:9157) at android.view.ViewRootImpl.enqueueInputEvent (ViewRootImpl.java:9126) at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent (ViewRootImpl.java:9329) at android.view.InputEventReceiver.dispatchInputEvent (InputEventReceiver.java:267) at android.os.MessageQueue.nativePollOnce at android.os.MessageQueue.next (MessageQueue.java:335) at android.os.Looper.loopOnce (Looper.java:161) at android.os.Looper.loop (Looper.java:288) at android.app.ActivityThread.main (ActivityThread.java:7918) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:936) Signed-off-by: Marcel Hibbe --- app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt index 7594df22f..984abb5bc 100644 --- a/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/chat/ChatActivity.kt @@ -1195,8 +1195,10 @@ class ChatActivity : this, object : MessageSwipeActions { override fun showReplyUI(position: Int) { - val chatMessage = adapter?.items?.get(position)?.item as ChatMessage? - replyToMessage(chatMessage) + val chatMessage = adapter?.items?.getOrNull(position)?.item as ChatMessage? + if (chatMessage != null) { + replyToMessage(chatMessage) + } } } )