NullPointerException in ChatActivity.onPrepareOptionsMenu when currentConversation is not yet loaded
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- android, kotlin
- Domain
- mobile-dev
Research direction
Start in ChatActivity.kt at onPrepareOptionsMenu, especially line 2731, and inspect the existing nullable currentConversation handling nearby. Reproduce the issue with the described instrumented navigation or automated test setup. Done means opening ChatActivity while the conversation is still loading no longer throws a NullPointerException and the unified-search menu visibility remains correct.
Written by the indexing model from the issue text.
Description
Summary
ChatActivity crashes with NullPointerException in onPrepareOptionsMenu when the menu is prepared before currentConversation is fully loaded. The crash is reliably reproducible on master by opening any conversation in an automated test environment (instrumented test, faster than human navigation).
Reproduction
- Build current
master(tested at HEAD5aeace618 bump version to 23.0.0). - Launch
ChatActivityprogrammatically (e.g. from an instrumented test, or by navigating from the conversation list very quickly). - The activity crashes before fully rendering.
Stack trace
java.lang.NullPointerException
at com.nextcloud.talk.chat.ChatActivity.onPrepareOptionsMenu(ChatActivity.kt:2731)
at android.app.Activity.onPreparePanel(Activity.java:4480)
at androidx.activity.ComponentActivity.onPreparePanel(ComponentActivity.kt:464)
at androidx.appcompat.view.WindowCallbackWrapper.onPreparePanel(WindowCallbackWrapper.java:99)
at androidx.appcompat.app.AppCompatDelegateImpl$AppCompatWindowCallback.onPreparePanel(...)
at androidx.appcompat.app.ToolbarActionBar.populateOptionsMenu(ToolbarActionBar.java:459)
at androidx.appcompat.app.ToolbarActionBar$1.run(ToolbarActionBar.java:58)
Root cause
ChatActivity.kt:2731 uses a non-null assertion on currentConversation:
searchItem.isVisible =
hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.UNIFIED_SEARCH) &&
currentConversation!!.remoteServer.isNullOrEmpty() && // ← !! crashes when currentConversation is null
!isChatThread()
onPrepareOptionsMenu is called by the system as soon as the toolbar is drawn, but the conversation is loaded asynchronously. Under fast/automated navigation, the menu is prepared before currentConversation is set.
Suggested fix
Either guard the whole block with currentConversation?.let { ... }, or use safe-call on the field:
searchItem.isVisible =
hasSpreedFeatureCapability(spreedCapabilities, SpreedFeatures.UNIFIED_SEARCH) &&
(currentConversation?.remoteServer?.isNullOrEmpty() ?: true) &&
!isChatThread()
(Several other currentConversation?.… calls already exist in the same method, suggesting this !! is an oversight rather than an invariant.)
Suspected commit
Likely introduced by 96b4f4308 New chat architecture + replace ChatKit with Compose + chat relay via signaling, which restructured ChatActivity.
Environment
- talk-android master @
5aeace618 - Android 13 / API 33 emulator (Pixel 3a, headless)
- Reproduced via instrumented
androidx.testUI navigation
- Dominant language
- Kotlin
- Stars
- 739
- Forks
- 321
- Avg merge
- 17h 28m
- Merged PRs (30d)
- 152
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from nextcloud/talk-android
-
1. to develop
Difficulty 3/5 1-2 days Newbie friendliness 68/100
nextcloud/talk-android#6739 ·
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 45/100
nextcloud/talk-android#6738 · 4 comments ·
-
0. Needs triage bug
Difficulty 3/5 1-2 days Newbie friendliness 52/100
nextcloud/talk-android#6729 ·
-
enhancement
nextcloud/talk-android#6718 · 2 comments · 1 assignee ·
-
Account removed automatically when it shouldn't: "Credentials for this account were no longer valid" Openbug
Difficulty 4/5 3-5 days Newbie friendliness 38/100
nextcloud/talk-android#6716 · 1 comment · 1 reaction ·
All issues in nextcloud/talk-android
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
bitcoindevkit/bdk-ffi#1125 ·
-
helsemelding-json-schema json-schema-core
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
contributor: external needs review
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100