Skip to content

fix(chat): guard null check operators to prevent crash on uninitialized chat#33

Merged
using-system merged 2 commits intomainfrom
fix/null-check-crash
Apr 21, 2026
Merged

fix(chat): guard null check operators to prevent crash on uninitialized chat#33
using-system merged 2 commits intomainfrom
fix/null-check-crash

Conversation

@using-system
Copy link
Copy Markdown
Owner

@using-system using-system commented Apr 21, 2026

Summary

  • Replace unsafe ! null assertions on _chat, _pendingAudioPath, and _pendingImagePath with local captures and early returns
  • Fixes a FATAL crash (Null check operator used on a null value) reported in Firebase Crashlytics on v1.14.0
  • Root cause: all three model init attempts could fail in _createChat(), leaving _chat null, or a concurrent skill-config reload could nullify _chat mid-send

Test plan

  • Open the app and send a text message — verify it works normally
  • Toggle a skill while a conversation is open — verify no crash
  • Force model init failure (e.g. delete model file) and try to send a message — verify graceful handling instead of crash
  • Send an image and audio message — verify they work normally

🤖 Generated with Claude Code

…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>
Copilot AI review requested due to automatic review settings April 21, 2026 11:06
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 _chat into a local variable before use and early-return when null in history loading, message sending, and response streaming paths.
  • Capture _pendingAudioPath / _pendingImagePath locally and early-return when null before reading media files.
  • Update streaming/tool-call handling to use the captured chat instance rather than _chat!.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/features/chat/presentation/conversation_page.dart
Comment thread lib/features/chat/presentation/conversation_page.dart Outdated
Comment thread lib/features/chat/presentation/conversation_page.dart
Comment thread lib/features/chat/presentation/conversation_page.dart Outdated
Comment thread lib/features/chat/presentation/conversation_page.dart
- 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>
@using-system using-system merged commit 8921d23 into main Apr 21, 2026
3 checks passed
@using-system using-system deleted the fix/null-check-crash branch April 21, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants