diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt index 65673e90ecf..93bcdd76615 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/KotlinCacheServiceImpl.kt @@ -307,10 +307,15 @@ class KotlinCacheServiceImpl(val project: Project) : KotlinCacheService { } private fun getFacadeForSyntheticFiles(files: Set): ProjectResolutionFacade { - synchronized(syntheticFileCachesLock) { + val cachedValue = synchronized(syntheticFileCachesLock) { //NOTE: computations inside createCacheForSyntheticFiles depend on project root structure // so we additionally drop the whole slru cache on change - return CachedValuesManager.getManager(project).getCachedValue(project, syntheticFilesCacheProvider).get(files) + CachedValuesManager.getManager(project).getCachedValue(project, syntheticFilesCacheProvider) + } + // In Upsource, we create multiple instances of KotlinCacheService, which all access the same CachedValue instance (UP-8046) + // To avoid race conditions, we can't use the local lock to access the cached value contents. + synchronized(cachedValue) { + return cachedValue.get(files) } }