fix: guard postSync() against uninitialized mTask#412
Open
7MS8 wants to merge 1 commit into
Open
Conversation
WorkManager can dispatch a follow-up task run whose lookup finds no task (id 0 or a deleted task). doWork() then takes the "no task" branch, mTask is never assigned, and postSync() unconditionally reads mTask.onSuccessFollowup / mTask.onFailFollowup, crashing with UninitializedPropertyAccessException. Guard both follow-up calls with mTask.isInitialized and set FAILURE_REASON.NO_TASK so the correct failure notification is shown instead. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Split out of #406 per reviewer request (separate unrelated fixes into their own PRs).
Bug
WorkManagercan dispatch a follow-upSyncWorkerrun for which the task lookup finds nothing (e.g. task id0, or the task was deleted between scheduling and execution).doWork()then takes the "no task" branch andmTask(alateinit var) is never assigned.postSync()unconditionally readsmTask.onSuccessFollowup/mTask.onFailFollowupin both the success and failure paths, which throwsUninitializedPropertyAccessExceptionand crashes the worker.Fix
Guard both follow-up-task calls in
postSync()withif (::mTask.isInitialized), and setfailureReason = FAILURE_REASON.NO_TASKin the "no task" branch ofdoWork()so the correct failure notification/reason is surfaced instead of falling through to the default "unknown" failure content.Reproduction
SyncWorkerrun with no resolvable task, e.g. via the exported broadcast receiver with an invalid/stale task id:UninitializedPropertyAccessExceptioninpostSync().Test plan
./gradlew :app:compileOssDebugSources).