[AA] AbstractSymbolTest: fix race

^KT-54311
This commit is contained in:
Dmitrii Gridin
2022-11-03 12:18:24 +01:00
committed by Space Team
parent 47c9618b79
commit 7d1ac0ac97
2 changed files with 9 additions and 9 deletions
@@ -57,14 +57,16 @@ abstract class AbstractSymbolTest : AbstractAnalysisApiSingleFileTest() {
} }
fun KtSymbol.safePointer(): PointerWrapper? { fun KtSymbol.safePointer(): PointerWrapper? {
val regularPointer = runCatching(::createPointer).let { val regularPointer = runCatching {
KtPsiBasedSymbolPointer.withDisabledPsiBasedPointers(disable = false, action = ::createPointer)
}.let {
if (directiveToIgnoreSymbolRestore == null) it.getOrThrow() else it.getOrNull() if (directiveToIgnoreSymbolRestore == null) it.getOrThrow() else it.getOrNull()
} ?: return null } ?: return null
val nonPsiPointer = kotlin.runCatching { val nonPsiPointer = kotlin.runCatching {
if (this is KtFileSymbol) return@runCatching null if (this is KtFileSymbol) return@runCatching null
KtPsiBasedSymbolPointer.withDisabledPsiBasedPointers(::createPointer) KtPsiBasedSymbolPointer.withDisabledPsiBasedPointers(disable = true, action = ::createPointer)
} }
return PointerWrapper( return PointerWrapper(
@@ -56,13 +56,11 @@ public class KtPsiBasedSymbolPointer<S : KtSymbol> private constructor(private v
@TestOnly @TestOnly
@Synchronized @Synchronized
public fun <T> withDisabledPsiBasedPointers(action: () -> T): T { public fun <T> withDisabledPsiBasedPointers(disable: Boolean, action: () -> T): T = try {
disablePsiPointer = true disablePsiPointer = disable
return try { action()
action() } finally {
} finally { disablePsiPointer = false
disablePsiPointer = false
}
} }
@Volatile @Volatile