[stable-25.0.x] Bugfix/noid/fix npe for get message - #6598
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of PR #6592