From eb4f322c7732afd6cd9cf4c42c22adeb77cb42ba Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Thu, 1 Jun 2017 17:13:35 +0300 Subject: [PATCH] Do not store ProcessCanceledException as result for cached value --- .../kotlin/storage/LockBasedStorageManager.java | 15 ++++++++++++++- .../org/jetbrains/kotlin/utils/exceptionUtils.kt | 8 ++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/core/util.runtime/src/org/jetbrains/kotlin/storage/LockBasedStorageManager.java b/core/util.runtime/src/org/jetbrains/kotlin/storage/LockBasedStorageManager.java index bb6cf36c67f..fe8af81541e 100644 --- a/core/util.runtime/src/org/jetbrains/kotlin/storage/LockBasedStorageManager.java +++ b/core/util.runtime/src/org/jetbrains/kotlin/storage/LockBasedStorageManager.java @@ -326,6 +326,12 @@ public class LockBasedStorageManager implements StorageManager { return typedValue; } catch (Throwable throwable) { + if (ExceptionUtilsKt.isProcessCanceledException(throwable)) { + value = NotValue.NOT_COMPUTED; + //noinspection ConstantConditions + throw (RuntimeException)throwable; + } + if (value == NotValue.COMPUTING) { // Store only if it's a genuine result, not something thrown through recursionDetected() value = WrappedValues.escapeThrowable(throwable); @@ -414,7 +420,14 @@ public class LockBasedStorageManager implements StorageManager { return typedValue; } catch (Throwable throwable) { - if (throwable == error) throw storageManager.exceptionHandlingStrategy.handleException(throwable); + if (ExceptionUtilsKt.isProcessCanceledException(throwable)) { + cache.remove(input); + //noinspection ConstantConditions + throw (RuntimeException)throwable; + } + if (throwable == error) { + throw storageManager.exceptionHandlingStrategy.handleException(throwable); + } Object oldValue = cache.put(input, WrappedValues.escapeThrowable(throwable)); if (oldValue != NotValue.COMPUTING) { diff --git a/core/util.runtime/src/org/jetbrains/kotlin/utils/exceptionUtils.kt b/core/util.runtime/src/org/jetbrains/kotlin/utils/exceptionUtils.kt index 2bda56778fb..6e0982f24f4 100644 --- a/core/util.runtime/src/org/jetbrains/kotlin/utils/exceptionUtils.kt +++ b/core/util.runtime/src/org/jetbrains/kotlin/utils/exceptionUtils.kt @@ -39,3 +39,11 @@ fun closeQuietly(closeable: Closeable?) { } } } + +fun Throwable.isProcessCanceledException(): Boolean { + var klass: Class = this.javaClass + while (true) { + if (klass.canonicalName == "com.intellij.openapi.progress.ProcessCanceledException") return true + klass = klass.superclass ?: return false + } +}