fix NPE after race condition. fixes #4033

This commit is contained in:
Daniel Gultsch 2021-03-13 11:13:19 +01:00
parent bf25b24967
commit 859f3b2a1d
2 changed files with 11 additions and 6 deletions

View file

@ -2992,6 +2992,11 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
final Menu menu = popupMenu.getMenu(); final Menu menu = popupMenu.getMenu();
menu.findItem(R.id.action_manage_accounts).setVisible(QuickConversationsService.isConversations()); menu.findItem(R.id.action_manage_accounts).setVisible(QuickConversationsService.isConversations());
popupMenu.setOnMenuItemClickListener(item -> { 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()) { switch (item.getItemId()) {
case R.id.action_show_qr_code: case R.id.action_show_qr_code:
activity.showQrCode(conversation.getAccount().getShareableUri()); activity.showQrCode(conversation.getAccount().getShareableUri());

View file

@ -17,7 +17,7 @@ import eu.siacs.conversations.ui.XmppActivity;
public class AccountUtils { public class AccountUtils {
public static final Class MANAGE_ACCOUNT_ACTIVITY; public static final Class<?> MANAGE_ACCOUNT_ACTIVITY;
static { static {
MANAGE_ACCOUNT_ACTIVITY = getManageAccountActivityClass(); MANAGE_ACCOUNT_ACTIVITY = getManageAccountActivityClass();
@ -78,7 +78,7 @@ public class AccountUtils {
return pending; return pending;
} }
public static void launchManageAccounts(Activity activity) { public static void launchManageAccounts(final Activity activity) {
if (MANAGE_ACCOUNT_ACTIVITY != null) { if (MANAGE_ACCOUNT_ACTIVITY != null) {
activity.startActivity(new Intent(activity, MANAGE_ACCOUNT_ACTIVITY)); activity.startActivity(new Intent(activity, MANAGE_ACCOUNT_ACTIVITY));
} else { } else {
@ -86,15 +86,15 @@ public class AccountUtils {
} }
} }
public static void launchManageAccount(XmppActivity xmppActivity) { public static void launchManageAccount(final XmppActivity xmppActivity) {
Account account = getFirst(xmppActivity.xmppConnectionService); final Account account = getFirst(xmppActivity.xmppConnectionService);
xmppActivity.switchToAccount(account); xmppActivity.switchToAccount(account);
} }
private static Class getManageAccountActivityClass() { private static Class<?> getManageAccountActivityClass() {
try { try {
return Class.forName("eu.siacs.conversations.ui.ManageAccountActivity"); return Class.forName("eu.siacs.conversations.ui.ManageAccountActivity");
} catch (ClassNotFoundException e) { } catch (final ClassNotFoundException e) {
return null; return null;
} }
} }