From 12e78f18d6352502c7cc942dc677f02bb9b8b257 Mon Sep 17 00:00:00 2001 From: Konstantin Nisht Date: Fri, 12 Apr 2024 15:40:32 +0200 Subject: [PATCH] [platform] IJPL-1039: extend `ProcessCanceledException` from `CancellationException` GitOrigin-RevId: 8edd7e83dc7029225e6d98f538428d6d6acfcc50 --- .../com/intellij/openapi/progress/coroutines.kt | 10 ++++++++++ .../manage/ExternalProjectsDataStorage.java | 5 ++--- .../daemon/impl/PassExecutorService.java | 2 +- .../indexing/contentQueue/IndexUpdateRunner.kt | 3 +++ .../com/intellij/ide/util/treeView/TreeState.java | 2 +- .../openapi/actionSystem/impl/ActionUpdater.kt | 3 +++ .../intellij/openapi/actionSystem/impl/Utils.kt | 3 +++ .../impl/NonBlockingReadActionImpl.java | 13 +------------ .../openapi/application/rw/InternalReadAction.kt | 2 -- .../fileTypes/impl/FileTypeManagerImpl.java | 2 +- .../openapi/progress/impl/PlatformTaskSupport.kt | 8 ++++---- .../openapi/vfs/newvfs/RefreshWorker.java | 2 +- .../application/PooledCoroutineContextTest.kt | 10 +--------- .../openapi/progress/CoroutineToIndicatorTest.kt | 4 ++-- .../progress/RunBlockingCancellableTest.kt | 15 ++++++++++++--- .../progress/RunWithModalProgressBlockingTest.kt | 4 ++-- .../openapi/progress/WithModalProgressTest.kt | 6 +++--- .../serviceContainer/ComponentManagerImpl.kt | 6 ++++++ platform/util/base/api-dump.txt | 2 +- .../progress/ProcessCanceledException.java | 9 ++++++--- .../src/org/jetbrains/concurrency/AsyncPromise.kt | 7 +++---- .../log/ui/actions/TwoStepCompletionProvider.java | 6 +++--- .../com/intellij/coverage/JavaCoverageEngine.java | 2 +- .../src/com/intellij/spellchecker/FileLoader.java | 3 +-- 24 files changed, 71 insertions(+), 58 deletions(-) diff --git a/platform/core-api/src/com/intellij/openapi/progress/coroutines.kt b/platform/core-api/src/com/intellij/openapi/progress/coroutines.kt index c1edf8bbb004..3b6efa69b398 100644 --- a/platform/core-api/src/com/intellij/openapi/progress/coroutines.kt +++ b/platform/core-api/src/com/intellij/openapi/progress/coroutines.kt @@ -131,6 +131,9 @@ private fun runBlockingCancellable(allowOrphan: Boolean, action: suspend Cor @Suppress("RAW_RUN_BLOCKING") runBlocking(ctx + readActionContext(), action) } + catch (pce: ProcessCanceledException) { + throw pce + } catch (ce: CancellationException) { throw CeProcessCanceledException(ce) } @@ -169,6 +172,9 @@ fun indicatorRunBlockingCancellable(indicator: ProgressIndicator, action: su @Suppress("RAW_RUN_BLOCKING") runBlocking(context + readActionContext(), action) } + catch (pce: ProcessCanceledException) { + throw pce + } catch (ce: CancellationException) { throw CeProcessCanceledException(ce) } @@ -375,11 +381,15 @@ suspend fun coroutineToIndicator(action: () -> T): T { */ @Internal @RequiresBlockingContext +@Throws(ProcessCanceledException::class) fun blockingContextToIndicator(action: () -> T): T { val ctx = currentThreadContext() return try { contextToIndicator(ctx, action) } + catch (pce : ProcessCanceledException) { + throw pce + } catch (ce: CancellationException) { throw CeProcessCanceledException(ce) } diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ExternalProjectsDataStorage.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ExternalProjectsDataStorage.java index 01a8414eac90..9d91bb9c0356 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ExternalProjectsDataStorage.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ExternalProjectsDataStorage.java @@ -1,4 +1,4 @@ -// Copyright 2000-2021 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. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.externalSystem.service.project.manage; import com.intellij.concurrency.ConcurrentCollectionFactory; @@ -21,7 +21,6 @@ import com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalS import com.intellij.openapi.externalSystem.settings.ExternalProjectSettings; import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil; import com.intellij.openapi.externalSystem.util.ExternalSystemUtil; -import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectUtil; import com.intellij.openapi.util.Pair; @@ -146,7 +145,7 @@ public final class ExternalProjectsDataStorage extends SimpleModificationTracker } } } - catch (ProcessCanceledException | CancellationException e) { + catch (CancellationException e) { throw e; } catch (Throwable e) { diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java index b5fc715f5398..802beff1585b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/PassExecutorService.java @@ -417,7 +417,7 @@ final class PassExecutorService implements Disposable { myPass.collectInformation(myUpdateProgress); } } - catch (ProcessCanceledException | CancellationException e) { + catch (CancellationException e) { cancelled = true; throw e; } diff --git a/platform/lang-impl/src/com/intellij/util/indexing/contentQueue/IndexUpdateRunner.kt b/platform/lang-impl/src/com/intellij/util/indexing/contentQueue/IndexUpdateRunner.kt index c9e84c61d3df..37acb1bca34e 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/contentQueue/IndexUpdateRunner.kt +++ b/platform/lang-impl/src/com/intellij/util/indexing/contentQueue/IndexUpdateRunner.kt @@ -104,6 +104,9 @@ class IndexUpdateRunner(private val myFileBasedIndex: FileBasedIndexImpl, @Suppress("RAW_RUN_BLOCKING") runBlocking(ctx + readActionContext(), action) } + catch (pce : ProcessCanceledException) { + throw pce + } catch (ce: CancellationException) { throw CeProcessCanceledException(ce) } diff --git a/platform/platform-api/src/com/intellij/ide/util/treeView/TreeState.java b/platform/platform-api/src/com/intellij/ide/util/treeView/TreeState.java index 1914773ec565..ac4811e4f7e3 100644 --- a/platform/platform-api/src/com/intellij/ide/util/treeView/TreeState.java +++ b/platform/platform-api/src/com/intellij/ide/util/treeView/TreeState.java @@ -323,7 +323,7 @@ public final class TreeState implements JDOMExternalizable { try { myPresentationData = readExternalPresentation(element); } - catch (ProcessCanceledException | CancellationException ignored) { + catch (CancellationException ignored) { } catch (Exception e) { LOG.warn("An error occurred while trying to read a cached tree presentation", e); diff --git a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionUpdater.kt b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionUpdater.kt index 825589e881a0..5430b5ef01c8 100644 --- a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionUpdater.kt +++ b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/ActionUpdater.kt @@ -611,6 +611,9 @@ internal class ActionUpdater @JvmOverloads constructor( try { return deferred.getCompleted() } + catch (pce : ProcessCanceledException) { + throw pce + } catch (ex: CancellationException) { throw CeProcessCanceledException(ex) } diff --git a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/Utils.kt b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/Utils.kt index 9addb99dbf41..c743fc9a2098 100644 --- a/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/Utils.kt +++ b/platform/platform-impl/src/com/intellij/openapi/actionSystem/impl/Utils.kt @@ -1238,6 +1238,9 @@ internal inline fun runBlockingForActionExpand(context: CoroutineContext = E @Suppress("RAW_RUN_BLOCKING") runBlocking(ctx + context + Context.current().asContextElement(), block) } + catch (pce : ProcessCanceledException) { + throw pce + } catch (ce: CancellationException) { throw CeProcessCanceledException(ce) } diff --git a/platform/platform-impl/src/com/intellij/openapi/application/impl/NonBlockingReadActionImpl.java b/platform/platform-impl/src/com/intellij/openapi/application/impl/NonBlockingReadActionImpl.java index 68421800a32a..19013ef9e76a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/impl/NonBlockingReadActionImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/application/impl/NonBlockingReadActionImpl.java @@ -522,7 +522,7 @@ public final class NonBlockingReadActionImpl implements NonBlockingReadAction } } } catch (ProcessCanceledException e) { - cancelJob(new PceCancellationException(e)); + cancelJob(e); throw e; } finally { @@ -667,17 +667,6 @@ public final class NonBlockingReadActionImpl implements NonBlockingReadAction private void failJob(@NotNull Throwable reason) { Continuation continuation = myChildContext.getContinuation(); if (continuation != null) { - if (reason instanceof ProcessCanceledException e) { - Job job = myChildContext.getJob(); - if (job != null) { - // Normally, any exception reported here goes directly to top-level `CoroutineExceptionHandlerImpl`. - // This is undesirable for PCE, which expresses cancellation, and not a fatal error. - // As a rule, PCE in continuation is handled in `runAsCoroutine`, but since we are opting for manual cancellation handling, - // we need to process PCE manually as well. - job.cancel(new PceCancellationException(e)); - return; - } - } continuation.resumeWith(new Result.Failure(reason)); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/application/rw/InternalReadAction.kt b/platform/platform-impl/src/com/intellij/openapi/application/rw/InternalReadAction.kt index f09128ef1ca5..f9c6aff33d92 100644 --- a/platform/platform-impl/src/com/intellij/openapi/application/rw/InternalReadAction.kt +++ b/platform/platform-impl/src/com/intellij/openapi/application/rw/InternalReadAction.kt @@ -6,8 +6,6 @@ import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.ModalityState import com.intellij.openapi.application.ReadConstraint import com.intellij.openapi.application.ex.ApplicationEx -import com.intellij.openapi.progress.PceCancellationException -import com.intellij.openapi.progress.ProcessCanceledException import com.intellij.openapi.progress.blockingContext import kotlinx.coroutines.* import kotlin.coroutines.coroutineContext diff --git a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java index 764404edc408..d4f167a45144 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java @@ -548,7 +548,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent fileType = ApplicationManager.getApplication().instantiateClass(bean.implementationClass, bean.getPluginDescriptor()); } } - catch (ProcessCanceledException | CancellationException e) { + catch (CancellationException e) { throw e; } catch (Exception e) { diff --git a/platform/platform-impl/src/com/intellij/openapi/progress/impl/PlatformTaskSupport.kt b/platform/platform-impl/src/com/intellij/openapi/progress/impl/PlatformTaskSupport.kt index de3504b3bd2b..6593f644c072 100644 --- a/platform/platform-impl/src/com/intellij/openapi/progress/impl/PlatformTaskSupport.kt +++ b/platform/platform-impl/src/com/intellij/openapi/progress/impl/PlatformTaskSupport.kt @@ -12,10 +12,7 @@ import com.intellij.openapi.application.impl.RawSwingDispatcher import com.intellij.openapi.application.impl.inModalContext import com.intellij.openapi.application.isModalAwareContext import com.intellij.openapi.diagnostic.logger -import com.intellij.openapi.progress.CeProcessCanceledException -import com.intellij.openapi.progress.ProgressIndicator -import com.intellij.openapi.progress.TaskInfo -import com.intellij.openapi.progress.prepareThreadContext +import com.intellij.openapi.progress.* import com.intellij.openapi.progress.util.* import com.intellij.openapi.progress.util.ProgressIndicatorWithDelayedPresentation.DEFAULT_PROGRESS_DIALOG_POSTPONE_TIME_MILLIS import com.intellij.openapi.project.Project @@ -118,6 +115,9 @@ class PlatformTaskSupport(private val cs: CoroutineScope) : TaskSupport { try { scope.runWithModalProgressBlockingInternal(dispatcher = null, descriptor, action) } + catch (pce: ProcessCanceledException) { + throw pce + } catch (ce: CancellationException) { throw CeProcessCanceledException(ce) } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshWorker.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshWorker.java index 607ec3d46ce5..e9163fc6e296 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshWorker.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/RefreshWorker.java @@ -124,7 +124,7 @@ final class RefreshWorker { processQueue(threadEvents); } catch (RefreshCancelledException ignored) { } - catch (ProcessCanceledException | CancellationException e) { + catch (CancellationException e) { myCancelled = true; } catch (Throwable t) { diff --git a/platform/platform-tests/testSrc/com/intellij/application/PooledCoroutineContextTest.kt b/platform/platform-tests/testSrc/com/intellij/application/PooledCoroutineContextTest.kt index 674df4e6b0c6..c5d2d43a6811 100644 --- a/platform/platform-tests/testSrc/com/intellij/application/PooledCoroutineContextTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/application/PooledCoroutineContextTest.kt @@ -2,10 +2,8 @@ package com.intellij.application import com.intellij.openapi.progress.ProcessCanceledException -import com.intellij.openapi.util.registry.Registry import com.intellij.testFramework.LightPlatformTestCase import com.intellij.testFramework.LoggedErrorProcessor -import com.intellij.testFramework.assertInstanceOf import com.intellij.util.getValue import com.intellij.util.setValue import kotlinx.coroutines.Dispatchers @@ -29,13 +27,7 @@ class PooledCoroutineContextTest : LightPlatformTestCase() { @Test fun `do not log ProcessCanceledException`() { val exception = ProcessCanceledException() - val logged = loggedErrorsAfterThrowingFromGlobalScope(exception) - if (Registry.`is`("ide.log.coroutine.pce")) { - assertSame(exception, assertInstanceOf(logged).cause) - } - else { - assertNull(logged) - } + assertNull(loggedErrorsAfterThrowingFromGlobalScope(exception)) } private fun loggedErrorsAfterThrowingFromGlobalScope(exception: Throwable): Throwable? = withNoopThreadUncaughtExceptionHandler { diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/progress/CoroutineToIndicatorTest.kt b/platform/platform-tests/testSrc/com/intellij/openapi/progress/CoroutineToIndicatorTest.kt index c041cad30d69..8a223a06e9af 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/progress/CoroutineToIndicatorTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/progress/CoroutineToIndicatorTest.kt @@ -70,12 +70,12 @@ class CoroutineToIndicatorTest : CancellationTest() { } private suspend inline fun testRunUnderIndicatorRethrow(t: ProcessCanceledException) { - val thrown = assertThrows { + val thrown = assertThrows { coroutineToIndicator { throw t } } - assertSame(t, thrown.cause) + assertSame(t, thrown) } @Test diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/progress/RunBlockingCancellableTest.kt b/platform/platform-tests/testSrc/com/intellij/openapi/progress/RunBlockingCancellableTest.kt index 8016b55cc47b..45bcd1ae087d 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/progress/RunBlockingCancellableTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/progress/RunBlockingCancellableTest.kt @@ -186,7 +186,7 @@ class RunBlockingCancellableTest : CancellationTest() { private fun testRunBlockingCancellableRethrow() { testRunBlockingCancellableRethrow(object : Throwable() {}) - testRunBlockingCancellableRethrow(CancellationException()) // manual CE + testRunBlockingCancellableRethrowPce(CancellationException()) // manual CE testRunBlockingCancellableRethrow(ProcessCanceledException()) // manual PCE } @@ -199,7 +199,7 @@ class RunBlockingCancellableTest : CancellationTest() { assertSame(t, thrown) } - private fun testRunBlockingCancellableRethrow(t: CancellationException) { + private fun testRunBlockingCancellableRethrowPce(t: CancellationException) { val thrown = assertThrows { runBlockingCancellable { throw t @@ -224,7 +224,8 @@ class RunBlockingCancellableTest : CancellationTest() { private fun testRunBlockingCancellableChildFailure() { testRunBlockingCancellableChildFailure(object : Throwable() {}) - testRunBlockingCancellableChildFailure(ProcessCanceledException()) + testRunBlockingCancellableChildDoesNotFailParent(CancellationException()) + testRunBlockingCancellableChildDoesNotFailParent(ProcessCanceledException()) } private inline fun testRunBlockingCancellableChildFailure(t: T) { @@ -236,6 +237,14 @@ class RunBlockingCancellableTest : CancellationTest() { assertSame(t, thrown) } + private fun testRunBlockingCancellableChildDoesNotFailParent(t: Throwable) { + assertDoesNotThrow { + runBlockingCancellable { + Job(parent = coroutineContext.job).completeExceptionally(t) + } + } + } + @Test fun `two neighbor calls the same thread restore context properly`(): Unit = timeoutRunBlocking { launch { diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/progress/RunWithModalProgressBlockingTest.kt b/platform/platform-tests/testSrc/com/intellij/openapi/progress/RunWithModalProgressBlockingTest.kt index 9970cf76ceae..f75fc987a32f 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/progress/RunWithModalProgressBlockingTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/progress/RunWithModalProgressBlockingTest.kt @@ -81,7 +81,7 @@ class RunWithModalProgressBlockingTest : ModalCoroutineTest() { fun rethrow(): Unit = timeoutRunBlocking { withContext(Dispatchers.EDT) { testRunWithModalProgressBlockingRethrow(object : Throwable() {}) - testRunWithModalProgressBlockingRethrow(CancellationException()) // manual CE + testRunWithModalProgressBlockingRethrowPce(CancellationException()) // manual CE testRunWithModalProgressBlockingRethrow(ProcessCanceledException()) // manual PCE } } @@ -95,7 +95,7 @@ class RunWithModalProgressBlockingTest : ModalCoroutineTest() { assertSame(t, thrown) } - private fun testRunWithModalProgressBlockingRethrow(t: CancellationException) { + private fun testRunWithModalProgressBlockingRethrowPce(t: CancellationException) { val thrown = assertThrows { runWithModalProgressBlocking { throw t diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/progress/WithModalProgressTest.kt b/platform/platform-tests/testSrc/com/intellij/openapi/progress/WithModalProgressTest.kt index 251c564ab164..3a2d2793792c 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/progress/WithModalProgressTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/openapi/progress/WithModalProgressTest.kt @@ -119,7 +119,7 @@ class WithModalProgressTest : ModalCoroutineTest() { @Test fun rethrow(): Unit = timeoutRunBlocking { testWithModalProgressRethrow(object : Throwable() {}) - testWithModalProgressRethrow(CancellationException()) // manual CE + testWithModalProgressRethrowPce(CancellationException()) // manual CE testWithModalProgressRethrow(ProcessCanceledException()) // manual PCE } @@ -132,8 +132,8 @@ class WithModalProgressTest : ModalCoroutineTest() { assertSame(t, thrown) } - private suspend fun testWithModalProgressRethrow(t: CancellationException) { - val thrown = assertThrows { + private suspend inline fun testWithModalProgressRethrowPce(t: T) { + val thrown = assertThrows { withModalProgress { throw t } diff --git a/platform/service-container/src/com/intellij/serviceContainer/ComponentManagerImpl.kt b/platform/service-container/src/com/intellij/serviceContainer/ComponentManagerImpl.kt index 6db15265b1d9..f7ea7dff7cb9 100644 --- a/platform/service-container/src/com/intellij/serviceContainer/ComponentManagerImpl.kt +++ b/platform/service-container/src/com/intellij/serviceContainer/ComponentManagerImpl.kt @@ -1614,6 +1614,9 @@ private inline fun rethrowCEasPCE(action: () -> X): X { try { return action() } + catch (pce : ProcessCanceledException) { + throw pce + } catch (ce: CancellationException) { throwAlreadyDisposedIfNotUnderIndicatorOrJob(cause = ce) throw CeProcessCanceledException(ce) @@ -1639,6 +1642,9 @@ private fun runBlockingInitialization(action: suspend CoroutineScope.() -> X @Suppress("RAW_RUN_BLOCKING") runBlocking(contextForInitializer, action) } + catch (pce : ProcessCanceledException) { + throw pce + } catch (ce: CancellationException) { throw CeProcessCanceledException(ce) } diff --git a/platform/util/base/api-dump.txt b/platform/util/base/api-dump.txt index 03277c2f388b..8ffbef954cda 100644 --- a/platform/util/base/api-dump.txt +++ b/platform/util/base/api-dump.txt @@ -12,7 +12,7 @@ f:com.intellij.filename.UniqueNameBuilder - size():I com.intellij.openapi.diagnostic.ControlFlowException c:com.intellij.openapi.progress.ProcessCanceledException -- java.lang.RuntimeException +- java.util.concurrent.CancellationException - com.intellij.openapi.diagnostic.ControlFlowException - ():V - p:(java.lang.String):V diff --git a/platform/util/base/src/com/intellij/openapi/progress/ProcessCanceledException.java b/platform/util/base/src/com/intellij/openapi/progress/ProcessCanceledException.java index 070760806cfb..011984f0a2f7 100644 --- a/platform/util/base/src/com/intellij/openapi/progress/ProcessCanceledException.java +++ b/platform/util/base/src/com/intellij/openapi/progress/ProcessCanceledException.java @@ -1,10 +1,12 @@ -// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.progress; import com.intellij.openapi.diagnostic.ControlFlowException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.concurrent.CancellationException; + /** * An exception indicating that the currently running operation was terminated and should finish as soon as possible. *

@@ -20,14 +22,15 @@ import org.jetbrains.annotations.Nullable; * @see com.intellij.openapi.progress.ProgressIndicator#checkCanceled() * @see General Threading Rules */ -public class ProcessCanceledException extends RuntimeException implements ControlFlowException { +public class ProcessCanceledException extends CancellationException implements ControlFlowException { public ProcessCanceledException() { } public ProcessCanceledException(@Nullable Throwable cause) { - super(cause); + super(cause == null ? null : cause.toString()); // repeat Throwable(Throwable) constructor logic if (cause instanceof ProcessCanceledException) { throw new IllegalArgumentException("Must not self-wrap ProcessCanceledException: ", cause); } + initCause(cause); } protected ProcessCanceledException(@NotNull String message) { diff --git a/platform/util/concurrency/src/org/jetbrains/concurrency/AsyncPromise.kt b/platform/util/concurrency/src/org/jetbrains/concurrency/AsyncPromise.kt index 090bea617508..3c5b64d75af3 100644 --- a/platform/util/concurrency/src/org/jetbrains/concurrency/AsyncPromise.kt +++ b/platform/util/concurrency/src/org/jetbrains/concurrency/AsyncPromise.kt @@ -52,13 +52,12 @@ open class AsyncPromise private constructor(internal val f: CompletableFuture // because of the contract: get() should return null for canceled promise private inline fun nullizeCancelled(value: () -> T?): T? { - if (isCancelled) { - return null - } - return try { value() } + catch (pce: ProcessCanceledException) { + throw pce + } catch (e: CancellationException) { null } diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/TwoStepCompletionProvider.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/TwoStepCompletionProvider.java index 70311230411a..c406660102e2 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/TwoStepCompletionProvider.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/TwoStepCompletionProvider.java @@ -48,9 +48,6 @@ public abstract class TwoStepCompletionProvider extends ValuesCompletionProvi break; } } - catch (InterruptedException | CancellationException e) { - break; - } catch (TimeoutException ignored) { } catch (ExecutionException e) { @@ -61,6 +58,9 @@ public abstract class TwoStepCompletionProvider extends ValuesCompletionProvi future.cancel(true); throw e; } + catch (InterruptedException | CancellationException e) { + break; + } } result.stopHere(); } diff --git a/plugins/coverage/src/com/intellij/coverage/JavaCoverageEngine.java b/plugins/coverage/src/com/intellij/coverage/JavaCoverageEngine.java index 68b0515de018..9a23b1c492a7 100644 --- a/plugins/coverage/src/com/intellij/coverage/JavaCoverageEngine.java +++ b/plugins/coverage/src/com/intellij/coverage/JavaCoverageEngine.java @@ -555,7 +555,7 @@ public class JavaCoverageEngine extends CoverageEngine { return createBriefReport(lineData, conditions, switches); } - catch (ProcessCanceledException | CancellationException e) { + catch (CancellationException e) { throw e; } catch (Exception e) { diff --git a/spellchecker/src/com/intellij/spellchecker/FileLoader.java b/spellchecker/src/com/intellij/spellchecker/FileLoader.java index 10e8e4eabec8..81183e0fcdce 100644 --- a/spellchecker/src/com/intellij/spellchecker/FileLoader.java +++ b/spellchecker/src/com/intellij/spellchecker/FileLoader.java @@ -2,7 +2,6 @@ package com.intellij.spellchecker; import com.intellij.openapi.diagnostic.Logger; -import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.spellchecker.dictionary.Loader; @@ -47,7 +46,7 @@ public final class FileLoader implements Loader { br.lines().forEach(consumer); } } - catch (ProcessCanceledException | CancellationException exception) { + catch (CancellationException exception) { throw exception; } catch (Exception e) {