calendar: guard async broadcast completion
- Commit
e2e9ff704b1ed6bb3b767d7c06ce2036812b4e85- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-19 04:10 UTC (17 days ago)
- Parents
fd06e1e
BroadcastReceiver.goAsync() is a platform type and can be null when a receiver is invoked outside a live broadcast dispatch, as in Robolectric tests. The boot and reminder receivers dereferenced it in finally blocks, so a null result threw NullPointerException after the real work and leaked as an uncaught coroutine exception into later tests. Use safe calls when finishing the pending results. This keeps live broadcast behaviour unchanged and prevents direct receiver invocation from failing after completion. Verified with :calendar:testDevUnitTest: 305 tests pass.
Diff
calendar/src/main/java/com/vayunmathur/calendar/platform/BootReceiver.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/platform/BootReceiver.kt b/calendar/src/main/java/com/vayunmathur/calendar/platform/BootReceiver.ktindex d014ca027f..2d466c3c55 100644--- a/calendar/src/main/java/com/vayunmathur/calendar/platform/BootReceiver.kt+++ b/calendar/src/main/java/com/vayunmathur/calendar/platform/BootReceiver.kt@@ -43,7 +43,7 @@ class BootReceiver : BroadcastReceiver() { if (unlocked) reconcileFromProvider(context, action) else armFromMirror(context, action) } finally {- pendingResult.finish()+ pendingResult?.finish() } } }
calendar/src/main/java/com/vayunmathur/calendar/platform/ReminderReceiver.kt
diff --git a/calendar/src/main/java/com/vayunmathur/calendar/platform/ReminderReceiver.kt b/calendar/src/main/java/com/vayunmathur/calendar/platform/ReminderReceiver.ktindex 78332c05d4..37fbe0adff 100644--- a/calendar/src/main/java/com/vayunmathur/calendar/platform/ReminderReceiver.kt+++ b/calendar/src/main/java/com/vayunmathur/calendar/platform/ReminderReceiver.kt@@ -95,7 +95,7 @@ class ReminderReceiver : BroadcastReceiver() { } catch (expected: Exception) { Log.error(TAG, "could not post reminder notification", expected) } finally {- pendingResult.finish()+ pendingResult?.finish() } } }