MemoryDiskConflictResolver: show the causing trace in tests

This commit is contained in:
peter
2017-06-12 21:35:30 +02:00
parent 6838c9f9f5
commit 1a7b35b718
@@ -49,6 +49,7 @@ import java.util.Set;
class MemoryDiskConflictResolver {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.fileEditor.impl.MemoryDiskConflictResolver");
private final Set<VirtualFile> myConflicts = new LinkedHashSet<>();
private Throwable myConflictAppeared;
void beforeContentChange(@NotNull VirtualFileEvent event) {
if (event.isFromSave()) return;
@@ -66,6 +67,9 @@ class MemoryDiskConflictResolver {
LOG.info(" documentStamp:" + documentStamp);
LOG.info(" oldFileStamp:" + oldFileStamp);
if (myConflicts.isEmpty()) {
if (ApplicationManager.getApplication().isUnitTestMode()) {
myConflictAppeared = new Throwable();
}
ApplicationManager.getApplication().invokeLater(this::processConflicts);
}
myConflicts.add(file);
@@ -86,9 +90,16 @@ class MemoryDiskConflictResolver {
FileDocumentManager.getInstance().reloadFromDisk(document);
}
}
myConflictAppeared = null;
}
boolean askReloadFromDisk(VirtualFile file, Document document) {
if (myConflictAppeared != null) {
Throwable trace = myConflictAppeared;
myConflictAppeared = null;
throw new IllegalStateException("Unexpected memory-disk conflict in tests, please use FileDocumentManager#reloadFromDisk or avoid VFS refresh", trace);
}
String message = UIBundle.message("file.cache.conflict.message.text", file.getPresentableUrl());
final DialogBuilder builder = new DialogBuilder();