Modern Apps git

← Modern-Apps.git

updater: don't NPE when goAsync returns no PendingResult

Commit
b3cc0531b5440dc06f418b45ccae762ab58dba9d
Author
Vayun Mathur <[email protected]>
When
2026-11-07 06:53 UTC (29 days ago)
Parents
8d0a3e0
UpdateBootReceiver called pending.finish() unconditionally in the
cleanup of its boot-completed coroutine. goAsync() returns null when
the receiver was not dispatched by the system (as under Robolectric,
and possible on-device for direct invocations), so the finally block
threw a NullPointerException on a background dispatcher, escaping as
an uncaught coroutine exception. Make the finish call null-safe.

Verified: the boot-receiver unit test that drives BOOT_COMPLETED
directly no longer logs the NPE, and the following Compose test in
the same JVM no longer sees an uncaught exception before it starts.

(cherry picked from commit 0d6ee01344af53f7dd4ec54c1f1728c91d0be40e)

Diff

updater/src/main/java/com/vayunmathur/updater/platform/UpdateBootReceiver.kt
diff --git a/updater/src/main/java/com/vayunmathur/updater/platform/UpdateBootReceiver.kt b/updater/src/main/java/com/vayunmathur/updater/platform/UpdateBootReceiver.ktindex 463738b095..fdae709cfd 100644--- a/updater/src/main/java/com/vayunmathur/updater/platform/UpdateBootReceiver.kt+++ b/updater/src/main/java/com/vayunmathur/updater/platform/UpdateBootReceiver.kt@@ -42,7 +42,9 @@ class UpdateBootReceiver : BroadcastReceiver() {                 // Whatever it was asking for, the restart has happened.                 UpdateNotifications.clearResult(appContext)             } finally {-                pending.finish()+                // goAsync() can return null (e.g. when not dispatched by the system); finishing+                // is best-effort and must not throw out of the cleanup path.+                pending?.finish()             }         }     }