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 <aleksei.cherepanov@jetbrains.com>
This commit is contained in:
Aleksei.Cherepanov
2022-02-04 09:42:05 +00:00
committed by Space
parent 6601b8b62c
commit a80d01265a
2 changed files with 22 additions and 1 deletions
@@ -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,
@@ -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<CommonCompilerArguments, String?>) {
initProject(LibraryDependency.JVM_MOCK_RUNTIME)