Project

General

Profile

Bug #561

NullPointerException (NPE) in Beem Android XMPP

Added by Danilo Dominguez over 5 years ago. Updated almost 2 years ago.

Status:
New
Priority:
High
Assignee:
-
Category:
XMPP
Target version:
-
Start date:
08/14/2014
Due date:
% Done:

0%

Estimated time:
Affected version:
0.1.8
Locale:
Close

Description

Dear Beem Team,

I have implemented an static analysis tool for finding bugs in Android apps and I have found a NullPointerException (NPE) in the following class of your app:
- com.beem.project.beem.ui.Chat

What steps will reproduce the problem?
1. Open the app with an account set up (I am using a google account).
2. Open a chat activity with a friend from your contact list.
3. Tab the menu button.
4. Tab OTR actions.
5. Tab the home button and before the window closes, tab Start OTR session.

This will create a NPE in the Chat activity. It is worth to mention that there are other scenarios in which this bug can be seen. For example, if the user repeat the first 4 steps and receives a phone call, but before the phone call activity takes the foreground, the user tabs in the option Start OTR session. This creates a race condition between the callbacks onPause and onOptionsItemSelected (onPause is called before onOptionsItemSelected). Other apps have had this problem as you can see in bug found in MyTracks [1].

To be more precise, mChatManager is set to null in onPause and then dereference in onOptionsItemSelected in:
try {
if (mChat == null) {
mChat = mChatManager.createChat(mContact, mMessageListener);
if (mChat != null) {
mChat.setOpen(true);
}
}
mChat.startOtrSession();
} catch (RemoteException e) {
Log.e(TAG, "start otr chats failed " + mChat, e);
}

To fix this problem check if the field mChatManager is not null in the callback onOptionsItemSelected.

try {
if (mChat == null && mChatManager != null) {
mChat = mChatManager.createChat(mContact, mMessageListener);
if (mChat != null) {
mChat.setOpen(true);
}
mChat.startOtrSession();
}
} catch (RemoteException e) {
Log.e(TAG, "start otr chats failed " + mChat, e);
}

What is the expected output? What do you see instead
The app crashes. The app must not crash and maintain the same state when the user comeback to the app.

What version of Beem are you using? On what Android version? On what device?
Beem 0.1.8 on a Samsung S4 Mini with Android 4.2.2.

Please provide any additional information below.

[1] https://code.google.com/p/mytracks/issues/detail?id=741&can=1&q=status%3AFixed&sort=id&colspec=ID%20Type%20Component%20Status%20Priority%20Targeting%20Work%20Stars%20Owner%20Summary&start=200

History

#1 Updated by Danilo Dominguez over 5 years ago

This behavior also happens in the class com.beem.project.beem.ui.ContactList with the field mXmppFacade.

Check case:
case R.id.contact_list_context_menu_call_item in onContextItemSelected and check if mXmppFacade != null

Also available in: Atom PDF