Skip to content

Conversation

sunkup
Copy link
Member

@sunkup sunkup commented Sep 23, 2025

Purpose

Fix IllegalThreadStateException during account rename.

Short description

The important change is in AccountRepository.rename():

withContext(defaultDispatcher) {
    automaticSyncManager.get().updateAutomaticSync(newAccount)
}

but please also check the @WorkerThread annotations make sense to you. We could annotate the whole AutomaticSyncManager class, but disableAutomaticSync() does not need an annotation, so only used in on the methods.

  • Ensured account settings are always created on a background thread by adding withContext and injected default dispatcher.
  • Added @WorkerThread annotations where deemed appropriate
  • Injected @DefaultDispatcher in for this issue relevant places of the app (not everywhere)
  • added tests. Mostly for verifying important methods were called. The more substantial ones are testRename_checksForAlreadyExisting and testRename_renamesAccountInAndroid. I think functionality of the other methods should be tested in their respective testclasses. If we were to test their functionality here in multiple test methods and additionally somewhere else we end up with a lot of dupliacated testing and tests.

Checklist

  • The PR has a proper title, description and label.
  • I have self-reviewed the PR.
  • I have added documentation to complex functions and functions that can be used by other modules.
  • I have added reasonable tests or consciously decided to not add tests.

@sunkup sunkup self-assigned this Sep 23, 2025
@sunkup sunkup added the bug Something isn't working label Sep 23, 2025
@sunkup sunkup linked an issue Sep 23, 2025 that may be closed by this pull request
@sunkup sunkup force-pushed the 1715-rename-account-causes-illegalthreadstateexception branch from ab8c8fd to 12fa988 Compare September 24, 2025 09:38
@sunkup sunkup requested a review from Copilot September 24, 2025 09:51
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes an IllegalThreadStateException during account rename by ensuring background thread execution and adding proper thread annotations.

  • Wraps automaticSyncManager.updateAutomaticSync() call in AccountRepository.rename() with withContext(defaultDispatcher) to ensure background thread execution
  • Adds @WorkerThread annotations to methods that require background thread execution
  • Replaces hardcoded Dispatchers.Default with injected @DefaultDispatcher for better testability and consistency

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
AccountRepository.kt Main fix: wraps automatic sync update in background context, adds WorkerThread annotation to createBlocking method
AutomaticSyncManager.kt Adds WorkerThread annotations to sync-related methods
TasksAppManager.kt Adds WorkerThread annotation to selectProvider method
LoginScreenModel.kt Replaces hardcoded Dispatchers.Default with injected defaultDispatcher
TasksModel.kt Replaces hardcoded Dispatchers.Default with injected defaultDispatcher
App.kt Replaces hardcoded Dispatchers.Default with injected defaultDispatcher
TestAccount.kt Makes account name configurable for testing
AccountRepositoryTest.kt Comprehensive test suite for rename functionality

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@sunkup sunkup marked this pull request as ready for review September 24, 2025 10:15
@sunkup sunkup requested review from Copilot and a team and removed request for Copilot September 24, 2025 10:15
Copy link
Member

@rfc2822 rfc2822 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, also the tests and that more dispatchers are injected.

One comment

@sunkup sunkup force-pushed the 1715-rename-account-causes-illegalthreadstateexception branch from f596f39 to ea15abc Compare September 28, 2025 14:03
@sunkup sunkup requested a review from a team September 28, 2025 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rename account causes IllegalThreadStateException
2 participants