Skip to content

Bugfix/noid/fix npe for get message - #6592

Merged
mahibi merged 2 commits into
masterfrom
bugfix/noid/fixNpeForGetMessage
Aug 27, 2026
Merged

Bugfix/noid/fix npe for get message#6592
mahibi merged 2 commits into
masterfrom
bugfix/noid/fixNpeForGetMessage

Conversation

@mahibi

@mahibi mahibi commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

getMessage's network fallback called getAndPersistMessages(bundle), which does bundle.getSerializable(KEY_FIELD_MAP) as HashMap<String, Int> - a non-null cast that throws NullPointerException when the key is absent. None of getMessage's callers (pinned message lookup, both getMessageById overloads in ChatViewModel) ever put KEY_FIELD_MAP into the bundle, so this crashed whenever the requested message wasn't already cached locally.

java.lang.NullPointerException
at OfflineFirstChatRepository.getAndPersistMessages (OfflineFirstChatRepository.kt:546)
at OfflineFirstChatRepository$getMessage$1.invokeSuspend (OfflineFirstChatRepository.kt:451)

Fetch the message directly via network.getContextForChatMessage instead, the same by-id lookup loadMessageContext already uses for this situation, rather than routing through the windowed pull API that getAndPersistMessages is meant for.

Assisted-by: Claude Code:claude-sonnet-5

馃弫 Checklist

  • 鉀戯笍 Tests (unit and/or integration) are included or not needed
  • 馃敄 Capability is checked or not needed
  • 馃敊 Backport requests are created or not needed: /backport to stable-xx.x
  • 馃搮 Milestone is set
  • 馃尭 PR title is meaningful (if it should be in the changelog: is it meaningful to users?)

馃 AI (if applicable)

  • The content of this PR was partly or fully generated using AI

mahibi added 2 commits August 27, 2026 10:12
getMessage's network fallback called getAndPersistMessages(bundle), which
does `bundle.getSerializable(KEY_FIELD_MAP) as HashMap<String, Int>` -
a non-null cast that throws NullPointerException when the key is absent.
None of getMessage's callers (pinned message lookup, both getMessageById
overloads in ChatViewModel) ever put KEY_FIELD_MAP into the bundle, so this
crashed whenever the requested message wasn't already cached locally.

java.lang.NullPointerException
  at OfflineFirstChatRepository.getAndPersistMessages (OfflineFirstChatRepository.kt:546)
  at OfflineFirstChatRepository$getMessage$1.invokeSuspend (OfflineFirstChatRepository.kt:451)

Fetch the message directly via network.getContextForChatMessage instead,
the same by-id lookup loadMessageContext already uses for this situation,
rather than routing through the windowed pull API that getAndPersistMessages
is meant for.

Assisted-by: Claude Code:claude-sonnet-5
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
getAndPersistMessages required its bundle to carry KEY_FIELD_MAP but only
enforced that via an unsafe cast, so a missing key surfaced as a bare
NullPointerException with no indication of what went wrong.

Its only remaining callers (initLongPolling, loadMoreMessages) are both
internal and already set the field map correctly, so this can only fire on
a future programming error - the right response is still to crash, not to
swallow it, but with a message that says why instead of an opaque NPE.

Document the precondition on the function and replace the cast with
requireNotNull.

Assisted-by: Claude Code:claude-sonnet-5
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
@mahibi mahibi added this to the 25.1.0 milestone Aug 27, 2026
@mahibi mahibi self-assigned this Aug 27, 2026
@mahibi mahibi added the 3. to review Waiting for reviews label Aug 27, 2026
@mahibi
mahibi marked this pull request as ready for review August 27, 2026 08:13
@mahibi
mahibi requested a review from rapterjet2004 August 27, 2026 08:14
@mahibi

mahibi commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator Author

/backport to stable-25.0.x

@github-actions

Copy link
Copy Markdown
Contributor

APK file: https://github.com/nextcloud/talk-android/actions/runs/33053103875/artifacts/9639148729
To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.
qrcode (please click on link to get QR code displayed)

@mahibi
mahibi merged commit dfe4463 into master Aug 27, 2026
17 of 21 checks passed
@mahibi
mahibi deleted the bugfix/noid/fixNpeForGetMessage branch August 27, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews AI assisted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants