From dca8627cc8d3eee4afd441a54b3b3dc884c10e1a Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 19 Mar 2018 12:35:29 +0100 Subject: [PATCH] =?UTF-8?q?AsyncPromise=20=E2=80=94=20ensure=20that=20setR?= =?UTF-8?q?esult/setError=20and=20blockingGet=20are=20not=20called=20insid?= =?UTF-8?q?e=20write=20action?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/org/jetbrains/concurrency/AsyncPromise.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/platform/projectModel-api/src/org/jetbrains/concurrency/AsyncPromise.kt b/platform/projectModel-api/src/org/jetbrains/concurrency/AsyncPromise.kt index bd78d9f94617..b61e03c61b17 100644 --- a/platform/projectModel-api/src/org/jetbrains/concurrency/AsyncPromise.kt +++ b/platform/projectModel-api/src/org/jetbrains/concurrency/AsyncPromise.kt @@ -1,6 +1,7 @@ // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.concurrency +import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.diagnostic.Logger import com.intellij.util.Function import org.jetbrains.concurrency.InternalPromiseUtil.PromiseValue @@ -96,6 +97,10 @@ open class AsyncPromise : InternalPromiseUtil.BasePromise(), Cancel } fun setResult(result: T) { + ApplicationManager.getApplication()?.let { + LOG.assertTrue(!it.isWriteAccessAllowed, "Result must be not set inside write-action") + } + if (!valueRef.compareAndSet(null, PromiseValue.createFulfilled(result))) { return } @@ -115,6 +120,10 @@ open class AsyncPromise : InternalPromiseUtil.BasePromise(), Cancel } open fun setError(error: Throwable): Boolean { + ApplicationManager.getApplication()?.let { + LOG.assertTrue(!it.isWriteAccessAllowed, "Error must be not set inside write-action") + } + if (!valueRef.compareAndSet(null, PromiseValue.createRejected(error))) { LOG.errorIfNotMessage(error) return false @@ -139,6 +148,10 @@ open class AsyncPromise : InternalPromiseUtil.BasePromise(), Cancel } override fun blockingGet(timeout: Int, timeUnit: TimeUnit): T? { + ApplicationManager.getApplication()?.let { + LOG.assertTrue(!it.isWriteAccessAllowed, "blockingGet() must be not called inside write-action") + } + var value = valueRef.get() if (value == null) { val latch = CountDownLatch(1)