fix(chat): guard null check operators to prevent crash on uninitialized chat#33
Merged
using-system merged 2 commits intomainfrom Apr 21, 2026
Merged
fix(chat): guard null check operators to prevent crash on uninitialized chat#33using-system merged 2 commits intomainfrom
using-system merged 2 commits intomainfrom
Conversation
…ed chat Replace unsafe `_chat!`, `_pendingAudioPath!`, and `_pendingImagePath!` assertions with local captures and early returns. The crash occurred when all three model init attempts failed in `_createChat()`, leaving `_chat` null, or when a concurrent skill-config reload nullified `_chat` mid-send. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR aims to prevent Null check operator used on a null value crashes in the chat conversation flow by removing unsafe ! assertions on _chat, _pendingAudioPath, and _pendingImagePath, replacing them with local captures and early returns.
Changes:
- Capture
_chatinto a local variable before use and early-return when null in history loading, message sending, and response streaming paths. - Capture
_pendingAudioPath/_pendingImagePathlocally and early-return when null before reading media files. - Update streaming/tool-call handling to use the captured
chatinstance rather than_chat!.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Move _streamAiResponse null check before inserting placeholder message - Set _chatError when all model init attempts fail instead of silently returning - Use _chat == chat identity check instead of _chat != null in tool call guards to detect stale instances after concurrent skill-config reloads Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
!null assertions on_chat,_pendingAudioPath, and_pendingImagePathwith local captures and early returnsNull check operator used on a null value) reported in Firebase Crashlytics on v1.14.0_createChat(), leaving_chatnull, or a concurrent skill-config reload could nullify_chatmid-sendTest plan
🤖 Generated with Claude Code