From 859f3b2a1dd0cdd2e92b1ac0b84173035b001cd3 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sat, 13 Mar 2021 11:13:19 +0100 Subject: [PATCH] fix NPE after race condition. fixes #4033 --- .../siacs/conversations/ui/ConversationFragment.java | 5 +++++ .../eu/siacs/conversations/utils/AccountUtils.java | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 4fa4d8185..82b9eb143 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -2992,6 +2992,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke final Menu menu = popupMenu.getMenu(); menu.findItem(R.id.action_manage_accounts).setVisible(QuickConversationsService.isConversations()); popupMenu.setOnMenuItemClickListener(item -> { + final XmppActivity activity = this.activity; + if (activity == null) { + Log.e(Config.LOGTAG,"Unable to perform action. no context provided"); + return true; + } switch (item.getItemId()) { case R.id.action_show_qr_code: activity.showQrCode(conversation.getAccount().getShareableUri()); diff --git a/src/main/java/eu/siacs/conversations/utils/AccountUtils.java b/src/main/java/eu/siacs/conversations/utils/AccountUtils.java index a324b242e..8f0453218 100644 --- a/src/main/java/eu/siacs/conversations/utils/AccountUtils.java +++ b/src/main/java/eu/siacs/conversations/utils/AccountUtils.java @@ -17,7 +17,7 @@ import eu.siacs.conversations.ui.XmppActivity; public class AccountUtils { - public static final Class MANAGE_ACCOUNT_ACTIVITY; + public static final Class MANAGE_ACCOUNT_ACTIVITY; static { MANAGE_ACCOUNT_ACTIVITY = getManageAccountActivityClass(); @@ -78,7 +78,7 @@ public class AccountUtils { return pending; } - public static void launchManageAccounts(Activity activity) { + public static void launchManageAccounts(final Activity activity) { if (MANAGE_ACCOUNT_ACTIVITY != null) { activity.startActivity(new Intent(activity, MANAGE_ACCOUNT_ACTIVITY)); } else { @@ -86,15 +86,15 @@ public class AccountUtils { } } - public static void launchManageAccount(XmppActivity xmppActivity) { - Account account = getFirst(xmppActivity.xmppConnectionService); + public static void launchManageAccount(final XmppActivity xmppActivity) { + final Account account = getFirst(xmppActivity.xmppConnectionService); xmppActivity.switchToAccount(account); } - private static Class getManageAccountActivityClass() { + private static Class getManageAccountActivityClass() { try { return Class.forName("eu.siacs.conversations.ui.ManageAccountActivity"); - } catch (ClassNotFoundException e) { + } catch (final ClassNotFoundException e) { return null; } }