@@ -32,6 +32,7 @@ private val LOG = logger<JdkLanguageSettings>()
3232
3333open class JdkLanguageSettings : LanguageSettings <JdkProjectSettings >() {
3434
35+ @Volatile
3536 protected var jdk: Sdk ? = null
3637 protected val sdkModel: ProjectSdksModel = createSdkModel()
3738
@@ -145,52 +146,58 @@ open class JdkLanguageSettings : LanguageSettings<JdkProjectSettings>() {
145146 jdkComboBox.isEnabled = false
146147
147148 runInBackground(course.project, EduJVMBundle .message(" progress.setting.suitable.jdk" ), false ) {
148- // Reset SDK model off-EDT to avoid IllegalStateException from synchronous progress on EDT
149149 try {
150- val project = course.project
151- if (project != null ) {
152- sdksModel.reset(project)
150+ // Reset SDK model off-EDT to avoid IllegalStateException from synchronous progress on EDT
151+ try {
152+ val project = course.project
153+ if (project != null ) {
154+ sdksModel.reset(project)
155+ }
156+ }
157+ catch (e: Throwable ) {
158+ loadingState = JdkLoadingState .FAILED
159+ // best-effort; if reset fails we'll try with whatever the model currently has
160+ loadingError = e.message
153161 }
154- }
155- catch (e: Throwable ) {
156- loadingState = JdkLoadingState .FAILED
157- // best-effort; if reset fails we'll try with whatever the model currently has
158- loadingError = e.message
159- }
160-
161- // Add bundled JDK if needed (must be done off-EDT as addSdk requires write action)
162- try {
163- addBundledJdkIfNeeded(sdksModel)
164- }
165- catch (_: Throwable ) {
166- // best-effort; ignore failures
167- }
168162
169- // If sdkModel is empty, try to get JDKs directly from ProjectJdkTable
170- val suitableJdk = findSuitableJdk(minJvmSdkVersion(course), sdksModel)
171- ? : findSuitableJdkFromTable(minJvmSdkVersion(course))
163+ // Add bundled JDK if needed (must be done off-EDT as addSdk requires write action)
164+ try {
165+ addBundledJdkIfNeeded(sdksModel)
166+ }
167+ catch (_: Throwable ) {
168+ // best-effort; ignore failures
169+ }
172170
173- // Check if we found any JDK at all (either suitable or any)
174- val anyJdkAvailable = sdksModel.sdks.any { it.sdkType == JavaSdk .getInstance() }
175- || ProjectJdkTable .getInstance().getSdksOfType( JavaSdk .getInstance()).isNotEmpty( )
171+ // If sdkModel is empty, try to get JDKs directly from ProjectJdkTable
172+ jdk = findSuitableJdk(minJvmSdkVersion(course), sdksModel)
173+ ? : findSuitableJdkFromTable(minJvmSdkVersion(course) )
176174
177- loadingState = if (anyJdkAvailable) JdkLoadingState .LOADED
178- else JdkLoadingState .FAILED
175+ // Check if we found any JDK at all (either suitable or any)
176+ if (sdksModel.sdks.all { it.sdkType != JavaSdk .getInstance() }
177+ && ProjectJdkTable .getInstance().getSdksOfType(JavaSdk .getInstance()).isEmpty()) {
178+ throw RuntimeException (EduJVMBundle .message(" error.no.jdk.available" ))
179+ }
179180
180- loadingError = if (anyJdkAvailable) null
181- else EduJVMBundle .message( " error.no.jdk.available " )
181+ loadingState = JdkLoadingState . LOADED
182+ loadingError = null
182183
183- runInBackground(course.project, EduJVMBundle .message(" progress.warming.suitable.jdk" ), false ) {
184- // Pre-warm SDK validation and VFS lookups off the EDT to avoid slow operations during UI rendering
185- prewarmSdkValidation(suitableJdk)
184+ runInBackground(course.project, EduJVMBundle .message(" progress.warming.suitable.jdk" ), false ) {
185+ // Pre-warm SDK validation and VFS lookups off the EDT to avoid slow operations during UI rendering
186+ prewarmSdkValidation(jdk)
187+ }
186188 }
189+ catch (e: Throwable ) {
190+ LOG .warn(" Failed to preselect JDK" , e)
191+ loadingState = JdkLoadingState .FAILED
192+ loadingError = e.message
193+ }
194+ finally {
195+ invokeLater(ModalityState .any()) {
196+ jdkComboBox.isEnabled = true
197+ jdkComboBox.selectedJdk = jdk
187198
188- invokeLater(ModalityState .any()) {
189- jdkComboBox.isEnabled = true
190- jdkComboBox.selectedJdk = suitableJdk
191- jdk = suitableJdk
192-
193- notifyListeners()
199+ notifyListeners()
200+ }
194201 }
195202 }
196203 }
0 commit comments