SDCardWalSyncImpl._getMissingWals - Null check crash#4538
Conversation
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>
There was a problem hiding this comment.
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.
| if (connection == null) { | ||
| Logger.debug("SDCard: Failed to establish connection for device info"); | ||
| return wals; | ||
| } |
There was a problem hiding this comment.
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
- 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.
Summary
Crash Stats
Test plan
🤖 Generated with Claude Code