Skip to content

SDCardWalSyncImpl._getMissingWals - Null check crash#4538

Merged
mdmohsin7 merged 1 commit intomainfrom
fix/ios-crash-sdcard-wal-sync-null-check
Feb 5, 2026
Merged

SDCardWalSyncImpl._getMissingWals - Null check crash#4538
mdmohsin7 merged 1 commit intomainfrom
fix/ios-crash-sdcard-wal-sync-null-check

Conversation

@aaravgarg
Copy link
Collaborator

Summary

  • Add null check for BLE connection result before calling getDeviceInfo
  • ensureConnection can return null when device is disconnected or unreachable
  • Return early with existing WALs instead of crashing

Crash Stats

Test plan

  • Verify SD card WAL sync still works when device is connected
  • Test with device going offline during sync (should not crash)

🤖 Generated with Claude Code

Check if ensureConnection returns null before calling getDeviceInfo
to prevent null check crash when BLE connection fails.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@aaravgarg aaravgarg requested a review from mdmohsin7 February 1, 2026 23:21
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly addresses a null-pointer crash in _getMissingWals by adding a null check after an attempt to establish a BLE connection. The fix is sound and prevents the application from crashing when the device is disconnected or unreachable. I've also included a suggestion to refactor the method for better performance by avoiding multiple redundant calls to establish the device connection, aligning with the rule to prefer using existing helper functions efficiently and avoiding repeated inlining of complex logic, which would improve efficiency and reduce battery usage.

Comment on lines +178 to +181
if (connection == null) {
Logger.debug("SDCard: Failed to establish connection for device info");
return wals;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

This null check correctly fixes the crash. However, looking at the context, the ensureConnection call on line 177 is the third such call in this method (the other two are inside _getStorageList on line 158 and _getAudioCodec on line 172). Each of these awaited calls can be a slow, battery-intensive operation.

To improve performance and reduce battery consumption, consider refactoring _getMissingWals to call ensureConnection only once at the beginning and pass the resulting connection object to the helper methods and for getting the device info.

References
  1. Prefer using existing helper functions over inlining their logic, especially when they handle complex cases like fallbacks or error handling. Inlining can introduce subtle bugs by missing parts of the original logic.

@mdmohsin7 mdmohsin7 merged commit c3f1b82 into main Feb 5, 2026
1 check passed
@mdmohsin7 mdmohsin7 deleted the fix/ios-crash-sdcard-wal-sync-null-check branch February 5, 2026 13:13
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