🔀 Commit

Fixed a crash when tapping a message menu action right after leaving the chat
Commit48933940882ba9e1393499f3f26c2f50460e9249
AuthorJabJab <noreply@xmpp.tel>
Date2026-09-03
Parentf9494bc5
commit 48933940882ba9e1393499f3f26c2f50460e9249
Author: JabJab <noreply@xmpp.tel>
Date:   Thu Sep 3 15:56:08 2026 +0300

    Fixed a crash when tapping a message menu action right after leaving the chat
---
 build.gradle                                               | 2 +-
 src/main/java/tel/xmpp/jabjab/ui/ConversationFragment.java | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/build.gradle b/build.gradle
index 162695a..813018b 100644
--- a/build.gradle
+++ b/build.gradle
@@ -113,7 +113,7 @@ android {
 
     defaultConfig {
         minSdkVersion 23
-        versionCode 42312
+        versionCode 42313
         versionName "1.0.7"
         applicationId "tel.xmpp.jabjab"
         resValue "string", "applicationId", applicationId
diff --git a/src/main/java/tel/xmpp/jabjab/ui/ConversationFragment.java b/src/main/java/tel/xmpp/jabjab/ui/ConversationFragment.java
index 3ff9171..1031c99 100644
--- a/src/main/java/tel/xmpp/jabjab/ui/ConversationFragment.java
+++ b/src/main/java/tel/xmpp/jabjab/ui/ConversationFragment.java
@@ -2648,6 +2648,13 @@ public class ConversationFragment extends XmppFragment
 
     @Override
     public boolean onContextItemSelected(MenuItem item) {
+        // Context menu item taps are delivered asynchronously — if the user backs out (or the
+        // fragment is otherwise torn down) between long-pressing a message and tapping an item,
+        // this can fire after the fragment has already been detached, and every branch below
+        // calls requireXmppActivity() unconditionally. Bail out instead of crashing.
+        if (!(getActivity() instanceof XmppActivity)) {
+            return false;
+        }
         return switch (item.getItemId()) {
             case R.id.share_with -> {
                 ShareUtil.share(requireXmppActivity(), selectedMessage);

Built with passion for open-source software, XMPP, privacy, and security —
the belief that people deserve communication tools that serve them, not surveil them.

Dedicated to every brave man and woman who stands up against tyranny and oppression across the world.
And in memory of those who were silenced before they could speak freely.