From 11b8ec6ec81680f996dae7bd5ca94b1ace7f007e Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 29 Jun 2017 22:09:33 +0200 Subject: [PATCH] try to provide a cause for PCE happening in disposable indicators e.g. daemon's --- .../util/AbstractProgressIndicatorBase.java | 16 ++++++++++++++-- .../progress/ProcessCanceledException.java | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/platform/core-impl/src/com/intellij/openapi/progress/util/AbstractProgressIndicatorBase.java b/platform/core-impl/src/com/intellij/openapi/progress/util/AbstractProgressIndicatorBase.java index d74c7c2b50ba..10bca4f54152 100644 --- a/platform/core-impl/src/com/intellij/openapi/progress/util/AbstractProgressIndicatorBase.java +++ b/platform/core-impl/src/com/intellij/openapi/progress/util/AbstractProgressIndicatorBase.java @@ -15,6 +15,7 @@ */ package com.intellij.openapi.progress.util; +import com.intellij.openapi.Disposable; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.application.TransactionGuard; @@ -25,13 +26,16 @@ import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.progress.impl.CoreProgressManager; +import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.UserDataHolderBase; import com.intellij.ui.mac.foundation.MacUtil; +import com.intellij.util.ObjectUtils; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.DoubleArrayList; import com.intellij.util.containers.Stack; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Set; @@ -127,15 +131,23 @@ public class AbstractProgressIndicatorBase extends UserDataHolderBase implements @Override public void checkCanceled() { if (isCanceled() && isCancelable()) { - throw new ProcessCanceledException(); + throw new ProcessCanceledException(getDisposeTrace()); } if (CoreProgressManager.runCheckCanceledHooks(this)) { if (isCanceled() && isCancelable()) { - throw new ProcessCanceledException(); + throw new ProcessCanceledException(getDisposeTrace()); } } } + @Nullable + private Throwable getDisposeTrace() { + if (this instanceof Disposable) { + return ObjectUtils.tryCast(Disposer.getTree().getDisposalInfo((Disposable)this), Throwable.class); + } + return null; + } + @Override public void setText(final String text) { myText = text; diff --git a/platform/util/src/com/intellij/openapi/progress/ProcessCanceledException.java b/platform/util/src/com/intellij/openapi/progress/ProcessCanceledException.java index 598fd86f2c61..de0e2f1ed52f 100644 --- a/platform/util/src/com/intellij/openapi/progress/ProcessCanceledException.java +++ b/platform/util/src/com/intellij/openapi/progress/ProcessCanceledException.java @@ -16,12 +16,12 @@ package com.intellij.openapi.progress; import com.intellij.openapi.diagnostic.ControlFlowException; -import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; public class ProcessCanceledException extends RuntimeException implements ControlFlowException { public ProcessCanceledException() { } - public ProcessCanceledException(@NotNull Throwable cause) { + public ProcessCanceledException(@Nullable Throwable cause) { super(cause); if (cause instanceof ProcessCanceledException) { throw new IllegalArgumentException("Must not self-wrap ProcessCanceledException: " + cause);