nextcloud / nextcloud/talk-android
NullPointerException in ChatActivity.onPrepareOptionsMenu when currentConversation is not yet loaded
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 739
- Forks
- 321
- Avg merge
- 14h 59m
- Merged PRs (30d)
- 151
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
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.
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.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100