[FIR] FirBasedSymbol: iterate annotations by index instead of iterator to avoid possible ConcurrentModificationException

^KT-56046
This commit is contained in:
Dmitrii Gridin
2023-01-31 14:23:57 +01:00
committed by Space Team
parent 19a61015c0
commit 38575cdbc1
2 changed files with 31 additions and 10 deletions
@@ -79,7 +79,17 @@ fun FirAnnotationContainer.resolvedAnnotationsWithArguments(anchorElement: FirBa
fun List<FirAnnotation>.resolvedAnnotationsWithArguments(anchorElement: FirBasedSymbol<*>): List<FirAnnotation> {
if (isEmpty()) return emptyList()
val phase = if (any { it is FirAnnotationCall && it.arguments.isNotEmpty() }) {
// this loop by index is required to avoid possible ConcurrentModificationException
var hasAnnotationCallWithArguments = false
for (i in indices) {
val currentAnnotation = get(i)
if (currentAnnotation is FirAnnotationCall && currentAnnotation.arguments.isNotEmpty()) {
hasAnnotationCallWithArguments = true
break
}
}
val phase = if (hasAnnotationCallWithArguments) {
FirResolvePhase.ANNOTATIONS_ARGUMENTS_MAPPING
} else {
FirResolvePhase.TYPES