Skip to content

fix: guard postSync() against uninitialized mTask#412

Open
7MS8 wants to merge 1 commit into
newhinton:masterfrom
7MS8:fix/postsync-uninitialized-mtask
Open

fix: guard postSync() against uninitialized mTask#412
7MS8 wants to merge 1 commit into
newhinton:masterfrom
7MS8:fix/postsync-uninitialized-mtask

Conversation

@7MS8

@7MS8 7MS8 commented Jul 8, 2026

Copy link
Copy Markdown

Split out of #406 per reviewer request (separate unrelated fixes into their own PRs).

Bug

WorkManager can dispatch a follow-up SyncWorker run for which the task lookup finds nothing (e.g. task id 0, or the task was deleted between scheduling and execution). doWork() then takes the "no task" branch and mTask (a lateinit var) is never assigned. postSync() unconditionally reads mTask.onSuccessFollowup / mTask.onFailFollowup in both the success and failure paths, which throws UninitializedPropertyAccessException and crashes the worker.

Fix

Guard both follow-up-task calls in postSync() with if (::mTask.isInitialized), and set failureReason = FAILURE_REASON.NO_TASK in the "no task" branch of doWork() so the correct failure notification/reason is surfaced instead of falling through to the default "unknown" failure content.

Reproduction

  • Trigger a SyncWorker run with no resolvable task, e.g. via the exported broadcast receiver with an invalid/stale task id:
    adb shell am broadcast -n <pkg>/ca.pkay.rcloneexplorer.BroadcastReceivers.SyncRestartAction --el task 0
  • Before this fix: worker crashes with UninitializedPropertyAccessException in postSync().
  • After this fix: worker completes cleanly and shows the "no task" failure notification.

Test plan

  • Local build compiles (./gradlew :app:compileOssDebugSources).
  • Trigger a sync broadcast with an invalid task id and confirm no crash, correct failure notification shown.

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>
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.

1 participant