Check VFS event for validity during async processing EA-109103

This commit is contained in:
Kirill Likhodedov
2017-10-11 15:17:56 +03:00
parent a4b2916186
commit 816f3118a7
@@ -17,6 +17,7 @@ package git4idea.repo;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
@@ -295,13 +296,18 @@ public class GitUntrackedFilesHolder implements Disposable, AsyncVfsEventsListen
@Nullable
private static VirtualFile getAffectedFile(@NotNull VFileEvent event) {
if (event instanceof VFileCreateEvent || event instanceof VFileDeleteEvent || event instanceof VFileMoveEvent || isRename(event)) {
return event.getFile();
} else if (event instanceof VFileCopyEvent) {
VFileCopyEvent copyEvent = (VFileCopyEvent) event;
return copyEvent.getNewParent().findChild(copyEvent.getNewChildName());
}
return null;
return ReadAction.compute(() -> {
if (!event.isValid()) return null;
if (event instanceof VFileCreateEvent || event instanceof VFileDeleteEvent || event instanceof VFileMoveEvent || isRename(event)) {
return event.getFile();
}
else if (event instanceof VFileCopyEvent) {
VFileCopyEvent copyEvent = (VFileCopyEvent) event;
return copyEvent.getNewParent().findChild(copyEvent.getNewChildName());
}
return null;
});
}
private static boolean isRename(@NotNull VFileEvent event) {