From 5390bfbeb0285fa40041ea577b77818ff042c761 Mon Sep 17 00:00:00 2001 From: Louis Vignier Date: Fri, 4 Jul 2025 14:51:45 +0900 Subject: [PATCH] [jdk] Fix default selected item in JDK download dialog #IDEA-375451 Fixed GitOrigin-RevId: 7c3d4d8e24d6add7bd99d7ba2546d92887b6393d --- .../impl/jdkDownloader/JdkDownloadDialog.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/jdkDownloader/JdkDownloadDialog.kt b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/jdkDownloader/JdkDownloadDialog.kt index 854b5da546ce..a3604b5158a2 100644 --- a/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/jdkDownloader/JdkDownloadDialog.kt +++ b/platform/lang-impl/src/com/intellij/openapi/projectRoots/impl/jdkDownloader/JdkDownloadDialog.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.projectRoots.impl.jdkDownloader import com.intellij.execution.wsl.WSLDistribution @@ -187,8 +187,14 @@ fun buildJdkDownloaderModel(allItems: List, itemFilter: (JdkItem) -> Bo val versionItems = groups.values .sortedWith(Comparator.comparing(Function { it.jdkVersion }, VersionComparatorUtil.COMPARATOR).reversed()) - val defaultItem = availableItems.firstOrNull { it.isDefaultItem } /* pick the newest default JDK */ - ?: availableItems.firstOrNull() /* pick just the newest JDK is no default was set (aka the JSON is broken) */ + val latestVersion = availableItems.filter { !it.isPreview }.maxByOrNull { it.jdkMajorVersion }?.jdkMajorVersion + val defaultItem = availableItems /* pick the newest OpenJDK */ + .filter { it.isDefaultItem } + .maxByOrNull { it.jdkMajorVersion } + ?: availableItems /* pick a "lightweight" non-preview JDK is no default is available */ + .filter { it.jdkMajorVersion == latestVersion && !it.isPreview } + .minByOrNull { it.archiveSize } + ?: availableItems.firstOrNull() /* strange case, e.g., only preview JDKs aren't filtered */ ?: error("There must be at least one JDK to install") /* totally broken JSON */ val defaultJdkVersionItem = versionItems.firstOrNull { group -> group.includedItems.any { it.item == defaultItem } }