diff: avoid possible issues with disposed RequestProcessor
authorAleksey Pivovarov <AMPivovarov@gmail.com>
Wed, 1 Jul 2015 14:35:31 +0000 (17:35 +0300)
committerAleksey Pivovarov <AMPivovarov@gmail.com>
Thu, 3 Sep 2015 16:28:10 +0000 (19:28 +0300)
platform/diff-impl/src/com/intellij/diff/impl/CacheDiffRequestChainProcessor.java
platform/diff-impl/src/com/intellij/diff/impl/DiffRequestProcessor.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/CacheChangeProcessor.java

index 8e37522288eb452a1315abb1769cc3248b12311c..5f609e50036f51f984cee5e9af81e41734e44cb0 100644 (file)
@@ -75,6 +75,8 @@ public abstract class CacheDiffRequestChainProcessor extends DiffRequestProcesso
 
   @CalledInAwt
   public void updateRequest(final boolean force, boolean useCache, @Nullable final ScrollToPolicy scrollToChangePolicy) {
+    if (isDisposed()) return;
+
     List<? extends DiffRequestProducer> requests = myRequestChain.getRequests();
     int index = myRequestChain.getIndex();
     if (index < 0 || index >= requests.size()) {
index a7b3912b8456970e33595b15d35727e916d6a273..1a3210e0c0b289708f17673a94fdd5277aa9ba67 100644 (file)
@@ -22,10 +22,7 @@ import com.intellij.diff.*;
 import com.intellij.diff.FrameDiffTool.DiffViewer;
 import com.intellij.diff.actions.impl.*;
 import com.intellij.diff.impl.DiffSettingsHolder.DiffSettings;
-import com.intellij.diff.requests.DiffRequest;
-import com.intellij.diff.requests.ErrorDiffRequest;
-import com.intellij.diff.requests.LoadingDiffRequest;
-import com.intellij.diff.requests.MessageDiffRequest;
+import com.intellij.diff.requests.*;
 import com.intellij.diff.tools.ErrorDiffTool;
 import com.intellij.diff.tools.external.ExternalDiffTool;
 import com.intellij.diff.tools.util.DiffDataKeys;
@@ -143,7 +140,7 @@ public abstract class DiffRequestProcessor implements Disposable {
     if (bottomPanel != null) myMainPanel.add(bottomPanel, BorderLayout.SOUTH);
     if (bottomPanel instanceof Disposable) Disposer.register(this, (Disposable)bottomPanel);
 
-    myState = new EmptyState();
+    myState = EmptyState.INSTANCE;
     myContentPanel.setContent(DiffUtil.createMessagePanel(((LoadingDiffRequest)myActiveRequest).getMessage()));
 
     myOpenInEditorAction = new OpenInEditorAction(new Runnable() {
@@ -398,6 +395,9 @@ public abstract class DiffRequestProcessor implements Disposable {
         myContentPanel.setContent(null);
 
         myActiveRequest.onAssigned(false);
+
+        myState = EmptyState.INSTANCE;
+        myActiveRequest = NoDiffRequest.INSTANCE;
       }
     });
   }
@@ -501,6 +501,10 @@ public abstract class DiffRequestProcessor implements Disposable {
     return mySettings;
   }
 
+  public boolean isDisposed() {
+    return myDisposed;
+  }
+
   //
   // Actions
   //
@@ -1017,6 +1021,8 @@ public abstract class DiffRequestProcessor implements Disposable {
   }
 
   private static class EmptyState implements ViewerState {
+    private static final EmptyState INSTANCE = new EmptyState();
+
     @Override
     public void init() {
     }
index 601be4e3eb679635a377a1db1fc436819fd397f9..5cbad999514bb1b44aed530e8ab305f12c9bc053 100644 (file)
@@ -86,6 +86,7 @@ public abstract class CacheChangeProcessor extends DiffRequestProcessor {
 
   @CalledInAwt
   public void updateRequest(final boolean force, boolean useCache, @Nullable final ScrollToPolicy scrollToChangePolicy) {
+    if (isDisposed()) return;
     final Change change = myCurrentChange;
 
     DiffRequest cachedRequest = loadRequestFast(change, useCache);