From 4a7aea0dc6cdf46db215c712792d8203e8af4641 Mon Sep 17 00:00:00 2001 From: Vladimir Dolzhenko Date: Mon, 3 Jul 2023 10:51:53 +0000 Subject: [PATCH] Change the order of final properties initialization and ctor To avoid case with NPE due to race-condition on publishing non-fully initialized object in ctor via `TypeRefinementSupport.Enabled(this)` #KT-59852 Merge-request: KT-MR-10917 Merged-by: Vladimir Dolzhenko --- .../jetbrains/kotlin/types/KotlinTypeRefinerImpl.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinTypeRefinerImpl.kt b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinTypeRefinerImpl.kt index 649c9234cee..e50741114ad 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/KotlinTypeRefinerImpl.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/KotlinTypeRefinerImpl.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.resolve.descriptorUtil.classId import org.jetbrains.kotlin.resolve.descriptorUtil.module import org.jetbrains.kotlin.resolve.scopes.MemberScope +import org.jetbrains.kotlin.storage.CacheWithNotNullValues import org.jetbrains.kotlin.storage.LockBasedStorageManager import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner @@ -25,6 +26,12 @@ class KotlinTypeRefinerImpl( private val moduleDescriptor: ModuleDescriptor, storageManager: StorageManager ) : KotlinTypeRefiner() { + private val refinedTypeCache: CacheWithNotNullValues = + storageManager.createCacheWithNotNullValues() + private val isRefinementNeededForTypeConstructorCache: CacheWithNotNullValues = + storageManager.createCacheWithNotNullValues() + private val scopes: CacheWithNotNullValues = + storageManager.createCacheWithNotNullValues() private var isStandalone: Boolean = false private constructor( @@ -41,10 +48,6 @@ class KotlinTypeRefinerImpl( } } - private val refinedTypeCache = storageManager.createCacheWithNotNullValues() - private val isRefinementNeededForTypeConstructorCache = storageManager.createCacheWithNotNullValues() - private val scopes = storageManager.createCacheWithNotNullValues() - /** * IMPORTANT: that function has not obvious contract: it refines only supertypes, * and don't refines type arguments, so return type is "partly refined".