From 6a65708631abaea5fbaa04c8f20b172a6370ced3 Mon Sep 17 00:00:00 2001 From: Dmitrii Gridin Date: Wed, 25 Jan 2023 14:36:07 +0100 Subject: [PATCH] [SLC] LazyAnnotationsBox: fix case with empty AnnotationsProvider ^KT-56046 --- .../symbol/annotations/LazyAnnotationsBox.kt | 30 ++++++++----------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/annotations/LazyAnnotationsBox.kt b/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/annotations/LazyAnnotationsBox.kt index 5041f5120df..f1786a49d58 100644 --- a/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/annotations/LazyAnnotationsBox.kt +++ b/analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/annotations/LazyAnnotationsBox.kt @@ -28,25 +28,21 @@ internal class LazyAnnotationsBox( SymbolLightLazyAnnotation(classId, annotationsProvider, index, owner) } - val valueToReturn = if (annotations.isEmpty()) { - setAnnotationsArray(PsiAnnotation.EMPTY_ARRAY) - } else { - synchronized(monitor) { - specialAnnotations?.forEach { specialAnnotation -> - val index = annotations.indexOfFirst { it.qualifiedName == specialAnnotation.qualifiedName } - if (index != -1) { - annotations[index] = specialAnnotation - } else { - annotations += specialAnnotation - } + val valueToReturn = synchronized(monitor) { + specialAnnotations?.forEach { specialAnnotation -> + val index = annotations.indexOfFirst { it.qualifiedName == specialAnnotation.qualifiedName } + if (index != -1) { + annotations[index] = specialAnnotation + } else { + annotations += specialAnnotation } - - val foundQualifiers = hashSetOf() - additionalAnnotationsProvider.addAllAnnotations(annotations, foundQualifiers, owner) - - specialAnnotations = null - setAnnotationsArray(annotations.toTypedArray()) } + + val foundQualifiers = annotations.mapNotNullTo(hashSetOf()) { it.qualifiedName } + additionalAnnotationsProvider.addAllAnnotations(annotations, foundQualifiers, owner) + + specialAnnotations = null + setAnnotationsArray(if (annotations.isNotEmpty()) annotations.toTypedArray() else PsiAnnotation.EMPTY_ARRAY) } return valueToReturn