Skip to content

[stable-25.0.x] Bugfix/noid/fix npe for get message - #6598

Merged
mahibi merged 2 commits into
stable-25.0.xfrom
backport/6592/stable-25.0.x
Aug 27, 2026
Merged

[stable-25.0.x] Bugfix/noid/fix npe for get message#6598
mahibi merged 2 commits into
stable-25.0.xfrom
backport/6592/stable-25.0.x

Conversation

@backportbot

@backportbot backportbot Bot commented Aug 27, 2026

Copy link
Copy Markdown

Backport of PR #6592

mahibi added 2 commits August 27, 2026 15:49
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>
@backportbot
backportbot Bot requested review from mahibi and rapterjet2004 August 27, 2026 15:49
@backportbot backportbot Bot added 3. to review Waiting for reviews AI assisted labels Aug 27, 2026
@backportbot backportbot Bot added this to the 25.0.0 milestone Aug 27, 2026
@mahibi
mahibi merged commit 4928b22 into stable-25.0.x Aug 27, 2026
10 of 15 checks passed
@mahibi
mahibi deleted the backport/6592/stable-25.0.x branch August 27, 2026 15:53
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.

1 participant