Bug #561
NullPointerException (NPE) in Beem Android XMPP
0%
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.