[Names] Avoid deadlock in initialization of classId constants

StandardClassIds was using Annotations subclass in its initialization.
At the same time, Annotations subclass was using StandardClassIds in its
initialization implicitly through baseId() method.

This leads to a rare deadlock on CI in case where two different threads
tried to initialize both classes at the same time.

It can't be reproduced robustly, as a single thread was able to
successfully initialize both, and will do it on an attempt to
initialize any of them.

^KT-64720 Fixed
This commit is contained in:
Pavel Kunyavskiy
2024-01-04 18:23:14 +01:00
committed by Space Team
parent 7accda6cda
commit 32de968531
3 changed files with 4 additions and 4 deletions
@@ -23,7 +23,7 @@ object FirJsReflectionAPICallChecker : AbstractFirReflectionApiCallChecker() {
override fun isAllowedReflectionApi(name: Name, containingClassId: ClassId, context: CheckerContext): Boolean {
return super.isAllowedReflectionApi(name, containingClassId, context) ||
containingClassId in StandardClassIds.associatedObjectAnnotations ||
containingClassId in StandardClassIds.Annotations.associatedObjectAnnotations ||
name == StandardNames.FqNames.findAssociatedObject.shortName()
}
@@ -93,8 +93,6 @@ object StandardClassIds {
val constantAllowedTypes = primitiveTypes + unsignedTypes + String
val associatedObjectAnnotations = hashSetOf(Annotations.AssociatedObjectKey, Annotations.ExperimentalAssociatedObjects)
val Continuation = "Continuation".coroutinesId()
@Suppress("FunctionName")
@@ -196,6 +194,8 @@ object StandardClassIds {
val AssociatedObjectKey = "AssociatedObjectKey".reflectId()
val ExperimentalAssociatedObjects = "ExperimentalAssociatedObjects".reflectId()
val associatedObjectAnnotations = hashSetOf(AssociatedObjectKey, ExperimentalAssociatedObjects)
object ParameterNames {
val value = Name.identifier("value")
@@ -41,7 +41,7 @@ class JsReflectionAPICallChecker(
context: CallCheckerContext
): Boolean {
return super.isAllowedReflectionApi(descriptor, containingClass, context) ||
containingClass.classId in StandardClassIds.associatedObjectAnnotations ||
containingClass.classId in StandardClassIds.Annotations.associatedObjectAnnotations ||
descriptor.name == StandardNames.FqNames.findAssociatedObject.shortName()
}