From b1f90229bd97fe61f512e088e2b52bfc938ea96e Mon Sep 17 00:00:00 2001 From: Jan Cizmar Date: Mon, 25 Nov 2024 16:10:00 +0100 Subject: [PATCH] fix: Prevent ConcurrentModificationException in InterceptedEventsManager (#2720) --- .../tolgee/activity/iterceptor/InterceptedEventsManager.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/data/src/main/kotlin/io/tolgee/activity/iterceptor/InterceptedEventsManager.kt b/backend/data/src/main/kotlin/io/tolgee/activity/iterceptor/InterceptedEventsManager.kt index 54dae5e62d..24acdf47ce 100644 --- a/backend/data/src/main/kotlin/io/tolgee/activity/iterceptor/InterceptedEventsManager.kt +++ b/backend/data/src/main/kotlin/io/tolgee/activity/iterceptor/InterceptedEventsManager.kt @@ -21,7 +21,7 @@ import io.tolgee.security.ProjectHolder import io.tolgee.security.ProjectNotSelectedException import io.tolgee.security.authentication.AuthenticationFacade import jakarta.persistence.EntityManager -import org.apache.commons.lang3.exception.ExceptionUtils.* +import org.apache.commons.lang3.exception.ExceptionUtils.getRootCause import org.hibernate.Transaction import org.hibernate.action.spi.BeforeTransactionCompletionProcess import org.hibernate.collection.spi.AbstractPersistentCollection @@ -31,6 +31,7 @@ import org.springframework.beans.factory.config.BeanDefinition.SCOPE_SINGLETON import org.springframework.context.ApplicationContext import org.springframework.context.annotation.Scope import org.springframework.stereotype.Component +import java.util.concurrent.ConcurrentHashMap import kotlin.reflect.KCallable import kotlin.reflect.full.findAnnotation import kotlin.reflect.full.hasAnnotation @@ -250,8 +251,8 @@ class InterceptedEventsManager( } } - private val annotatedMembersCache: MutableMap, Map> = mutableMapOf() - private val ignoredMembersCache: MutableMap, Set> = mutableMapOf() + private val annotatedMembersCache: ConcurrentHashMap, Map> = ConcurrentHashMap() + private val ignoredMembersCache: ConcurrentHashMap, Set> = ConcurrentHashMap() private fun shouldHandleActivity(entity: Any?) = entity is EntityWithId && entity::class.hasAnnotation() &&