IDEA-64883 Don't save document if it is null.
authorKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Fri, 8 Apr 2011 13:27:51 +0000 (17:27 +0400)
committerKirill Likhodedov <kirill.likhodedov@jetbrains.com>
Fri, 8 Apr 2011 13:29:01 +0000 (17:29 +0400)
platform/platform-api/src/com/intellij/openapi/fileEditor/FileDocumentManager.java
platform/platform-impl/src/com/intellij/openapi/fileEditor/impl/FileDocumentManagerImpl.java
platform/vcs-impl/src/com/intellij/openapi/vcs/actions/AbstractShowDiffAction.java

index f0181c23c35ad2f7d51994a6115726c3db6e4bef..243ad6dd4cfd5795c8c6bc6db58525e7cd58a534 100644 (file)
@@ -27,6 +27,7 @@ public abstract class FileDocumentManager {
     return ApplicationManager.getApplication().getComponent(FileDocumentManager.class);
   }
 
+  @Nullable
   public abstract Document getDocument(@NotNull VirtualFile file);
 
   @Nullable
index e4dae40553d652dc3a0dc346699910f6b208e637..294f158094609726f6461ffde84d9d3d41f0af27 100644 (file)
@@ -107,6 +107,7 @@ public class FileDocumentManagerImpl extends FileDocumentManager implements Appl
   public void disposeComponent() {
   }
 
+  @Nullable
   public Document getDocument(@NotNull final VirtualFile file) {
     DocumentEx document = (DocumentEx)getCachedDocument(file);
     if (document == null) {
index 1f1ba9523d020138a9edbfbef4e153242da14a02..392f1112fdac714bf78403152c56e86b4004ab5f 100644 (file)
@@ -17,6 +17,7 @@ package com.intellij.openapi.vcs.actions;
 
 import com.intellij.openapi.actionSystem.AnActionEvent;
 import com.intellij.openapi.actionSystem.Presentation;
+import com.intellij.openapi.editor.Document;
 import com.intellij.openapi.fileEditor.FileDocumentManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.vcs.AbstractVcs;
@@ -89,7 +90,10 @@ public abstract class AbstractShowDiffAction extends AbstractVcsAction{
     final Project project = vcsContext.getProject();
     final VirtualFile selectedFile = vcsContext.getSelectedFiles()[0];
     final FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
-    fileDocumentManager.saveDocument(fileDocumentManager.getDocument(selectedFile));
+    final Document document = fileDocumentManager.getDocument(selectedFile);
+    if (document != null) {
+      fileDocumentManager.saveDocument(document);
+    }
 
     final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
     final AbstractVcs vcs = vcsManager.getVcsFor(selectedFile);