Conversation
migrate to courutine instead of background tasks. https://plugins.jetbrains.com/docs/intellij/background-processes.html#progress-api
migrate to courutine instead of background tasks. https://plugins.jetbrains.com/docs/intellij/background-processes.html#progress-api
meanmail
left a comment
There was a problem hiding this comment.
Overview
The PR migrates JDK preselection in JdkLanguageSettings from the legacy runInBackground (ProgressManager-based background task) to Kotlin coroutines. It also adds request invalidation via AtomicInteger, guard checks for disposed UI components, and a syncSdksModelWithJdkTable helper.
Critical Issue
All heavy work now runs on EDT
The coroutine is launched with Dispatchers.EDT and all blocking operations (sdksModel.reset(), addBundledJdkIfNeeded, syncSdksModelWithJdkTable, prewarmSdkValidation) execute on the Event Dispatch Thread. The old code explicitly ran these in a background thread via runInBackground with the comment: "Reset SDK model off-EDT to avoid IllegalStateException from synchronous progress on EDT".
Dispatchers.EDT dispatches onto the Swing EDT. Since these are blocking (non-suspend) calls, they will block the UI thread — potentially causing freezes, especially sdksModel.reset(project) and VFS operations in prewarmSdkValidation.
The background work should use Dispatchers.Default or Dispatchers.IO, with only the UI updates (finishPreselectJdk) dispatched to EDT via withContext(Dispatchers.EDT).
Other Issues
See inline comments.
Why
|
| IntelliJ API pattern | Threading requirement |
|---|---|
ProgressManager.runProcessWithProgressSynchronously(...) |
EDT (shows modal dialog) |
ProgressManager.checkCanceled() |
Needs ProgressIndicator on thread - use coroutineToIndicator |
| Pure computation / data cloning | Any thread (Dispatchers.IO or Default) |
| VFS / filesystem access | Off EDT (Dispatchers.IO) |
| Swing component updates | EDT (Dispatchers.EDT or withContext(Dispatchers.Main)) |
Don't assume a single method like runInBackground { ... } had uniform threading needs - the block may contain calls with conflicting requirements. When it "worked", some parts may have been silently failing.
meanmail
left a comment
There was a problem hiding this comment.
Threading split looks correct now — reset/sync/find on IO, addBundledJdkIfNeeded on EDT, prewarm on IO. Nice work.
One bug and one minor issue remaining, see inline comments.
meanmail
left a comment
There was a problem hiding this comment.
Both issues fixed. LGTM!
meanmail
left a comment
There was a problem hiding this comment.
Re-approving after new commit. The additional changes (EAP version bump, plugin version 2026.9→2026.10, OpenProjectTask constructor adaptation for 261 API change) look fine.
Minor nit: import java.nio.file.Path in OpenProjectTaskCompat.kt appears unused — all Path? params are passed as null. Likely needed for constructor overload resolution at compile time, but worth a quick check if the build passes without it.
Old background task replaced by new courutines.