From aca13a18bfc7275efc185696de72dfe09aa5ac21 Mon Sep 17 00:00:00 2001 From: Louis Vignier Date: Fri, 6 Mar 2026 16:12:48 +0100 Subject: [PATCH] IDEA-386224 jdk: fix JDK_X case for LanguageLevel#getNonPreviewLevel IJ-CR-194679 (cherry picked from commit e7fed949dab6c28a2ddb31beb92a6158e3962569) IJ-CR-194679 GitOrigin-RevId: 1c7bd1cee637a5bfc92d002ccb3de6b4670b8954 --- .../intellij/pom/java/AcceptedLanguageLevelsSettings.java | 2 +- .../src/com/intellij/pom/java/LanguageLevel.kt | 8 ++++---- .../importing/GradleJavaCompilerSettingsImportingTest.kt | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/java/java-impl/src/com/intellij/pom/java/AcceptedLanguageLevelsSettings.java b/java/java-impl/src/com/intellij/pom/java/AcceptedLanguageLevelsSettings.java index a28da92c95ca..a4de8150fa0a 100644 --- a/java/java-impl/src/com/intellij/pom/java/AcceptedLanguageLevelsSettings.java +++ b/java/java-impl/src/com/intellij/pom/java/AcceptedLanguageLevelsSettings.java @@ -153,7 +153,7 @@ public final class AcceptedLanguageLevelsSettings implements PersistentStateComp if (ApplicationManager.getApplication().isEAP()) return true; // language levels up to HIGHEST are officially supported var nonPreviewLevel = languageLevel.getNonPreviewLevel(); - return nonPreviewLevel != null && JavaRelease.getHighest().compareTo(nonPreviewLevel) >= 0 || getSettings().acceptedNames.contains(languageLevel.name()); + return JavaRelease.getHighest().compareTo(nonPreviewLevel) >= 0 || getSettings().acceptedNames.contains(languageLevel.name()); } private static void acceptAndRestore(Project project, Collection modules, LanguageLevel languageLevel) { diff --git a/java/java-syntax/src/com/intellij/pom/java/LanguageLevel.kt b/java/java-syntax/src/com/intellij/pom/java/LanguageLevel.kt index bf0dcf5241e8..9e8a7ca1c5c7 100644 --- a/java/java-syntax/src/com/intellij/pom/java/LanguageLevel.kt +++ b/java/java-syntax/src/com/intellij/pom/java/LanguageLevel.kt @@ -123,11 +123,11 @@ enum class LanguageLevel { } /** - * @return corresponding non-preview level, `this` if this level is non-preview already, `null` if the level is unreleased and unsupported + * @return corresponding non-preview level, `this` for [JDK_X] and non-preview levels. */ - fun getNonPreviewLevel(): LanguageLevel? { - if (!isPreview) return this - return ourStandardVersions[myVersion.feature] + fun getNonPreviewLevel(): LanguageLevel { + if (!isPreview || this == JDK_X) return this + return requireNotNull(ourStandardVersions[myVersion.feature]) } val presentableText: @Nls String diff --git a/plugins/gradle/java/testSources/importing/GradleJavaCompilerSettingsImportingTest.kt b/plugins/gradle/java/testSources/importing/GradleJavaCompilerSettingsImportingTest.kt index 97fbdb085f3e..a203efa2bfd1 100644 --- a/plugins/gradle/java/testSources/importing/GradleJavaCompilerSettingsImportingTest.kt +++ b/plugins/gradle/java/testSources/importing/GradleJavaCompilerSettingsImportingTest.kt @@ -99,7 +99,7 @@ class GradleJavaCompilerSettingsImportingTest : GradleJavaCompilerSettingsImport @Test fun `test language level approximation`() { val highest = JavaRelease.getHighest() - val nonPreview = highest.getNonPreviewLevel()!! + val nonPreview = highest.getNonPreviewLevel() val preview = nonPreview.getPreviewLevel() Assume.assumeTrue("The IDE $highest Java version doesn't have preview level",