From a80d01265a5b24bb090de6f4dc48cf84de0e1f34 Mon Sep 17 00:00:00 2001 From: "Aleksei.Cherepanov" Date: Fri, 4 Feb 2022 09:42:05 +0000 Subject: [PATCH] Use possible incompatible metadata as a fallback for incremental analysis If LeverVersion is set to greater than 1 of the current compiler version, metadata became null here org.jetbrains.kotlin.load.kotlin.header.ReadKotlinClassHeaderAnnotationVisitor.createHeader, which leads to NPE during incremental analysis. Using the same incompatible data as fallback prevent it #KTIJ-20954 Fixed Merge-request: KT-MR-5680 Merged-by: Aleksei Cherepanov --- .../kotlin/incremental/IncrementalJvmCache.kt | 2 +- .../build/KotlinJpsBuildTestIncremental.kt | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/build-common/src/org/jetbrains/kotlin/incremental/IncrementalJvmCache.kt b/build-common/src/org/jetbrains/kotlin/incremental/IncrementalJvmCache.kt index 78b7c4297bf..d1bcaac7036 100644 --- a/build-common/src/org/jetbrains/kotlin/incremental/IncrementalJvmCache.kt +++ b/build-common/src/org/jetbrains/kotlin/incremental/IncrementalJvmCache.kt @@ -652,7 +652,7 @@ class KotlinClassInfo constructor( return KotlinClassInfo( classId, classHeader.kind, - classHeader.data ?: emptyArray(), + classHeader.data ?: classHeader.incompatibleData ?: emptyArray(), classHeader.strings ?: emptyArray(), classHeader.multifileClassName, constantsMap = constantsAndInlineFunctions.first, diff --git a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTestIncremental.kt b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTestIncremental.kt index 997b7e30cb1..89e1c526025 100644 --- a/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTestIncremental.kt +++ b/jps/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTestIncremental.kt @@ -148,6 +148,27 @@ class KotlinJpsBuildTestIncremental : KotlinJpsBuildTest() { languageOrApiVersionChanged(CommonCompilerArguments::apiVersion) } + @WorkingDir("LanguageOrApiVersionChanged") + fun testLanguageVersionExperimental() { + initProject(LibraryDependency.JVM_MOCK_RUNTIME) + val module = myProject.modules.first() + val args = module.kotlinCompilerArguments + + // Try to set Language version to Stable+2 (there is no promises that metadata will be supported) + val experimentalLevelVersion: LanguageVersion + try { + experimentalLevelVersion = LanguageVersion.values()[LanguageVersion.LATEST_STABLE.ordinal+2] + } catch (e: ArrayIndexOutOfBoundsException) { + // there is no Stable+2 version for now, skiping test + return + } + CommonCompilerArguments::languageVersion.set(args, experimentalLevelVersion.versionString) + myProject.kotlinCommonCompilerArguments = args + + buildAllModules().assertSuccessful() + assertCompiled(KotlinBuilder.KOTLIN_BUILDER_NAME, "src/Bar.kt", "src/Foo.kt") + } + private fun languageOrApiVersionChanged(versionProperty: KMutableProperty1) { initProject(LibraryDependency.JVM_MOCK_RUNTIME)