From 8d9abb37a661bea5cff96e4b6bfa660a4f6157dd Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 8 Sep 2015 17:12:01 +0200 Subject: [PATCH] yet more diagnostics for VfsData.initFile exceptions (IDEA-CR-4584, EA-70830) --- .../intellij/openapi/vfs/newvfs/impl/VfsData.java | 12 +++++++++--- .../vfs/newvfs/impl/VirtualDirectoryImpl.java | 9 +++++++-- .../vfs/newvfs/persistent/PersistentFSImpl.java | 4 ++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VfsData.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VfsData.java index b45c38c28e06..8cd0449808f8 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VfsData.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VfsData.java @@ -144,8 +144,14 @@ public class VfsData { if (segment != null || !create) return segment; return ourSegments.cacheOrGet(key, new Segment()); } + + public static class FileAlreadyCreatedException extends Exception { + private FileAlreadyCreatedException(String message) { + super(message); + } + } - public static void initFile(int id, Segment segment, int nameId, @NotNull Object data) { + public static void initFile(int id, Segment segment, int nameId, @NotNull Object data) throws FileAlreadyCreatedException { assert id > 0; int offset = getOffset(id); @@ -154,12 +160,12 @@ public class VfsData { Object existingData = segment.myObjectArray.get(offset); if (existingData != null) { int parent = FSRecords.getParent(id); - String msg = "File already created: " + existingData + "; parentId=" + parent; + String msg = "File already created: " + nameId + ", data=" + existingData + "; parentId=" + parent; if (parent > 0) { msg += "; parent.name=" + FSRecords.getName(parent); msg += "; parent.children=" + Arrays.toString(FSRecords.listAll(id)); } - throw new AssertionError(msg); + throw new FileAlreadyCreatedException(msg); } segment.myObjectArray.set(offset, data); } diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java index 807cacc1d226..02c40461b312 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/impl/VirtualDirectoryImpl.java @@ -216,8 +216,13 @@ public class VirtualDirectoryImpl extends VirtualFileSystemEntry { private VirtualFileSystemEntry createChild(int nameId, int id, @NotNull NewVirtualFileSystem delegate) { final int attributes = ourPersistence.getFileAttributes(id); VfsData.Segment segment = VfsData.getSegment(id, true); - VfsData.initFile(id, segment, nameId, - PersistentFS.isDirectory(attributes) ? new VfsData.DirectoryData() : KeyFMap.EMPTY_MAP); + try { + VfsData.initFile(id, segment, nameId, + PersistentFS.isDirectory(attributes) ? new VfsData.DirectoryData() : KeyFMap.EMPTY_MAP); + } + catch (VfsData.FileAlreadyCreatedException e) { + throw new RuntimeException("dir=" + myId + "; dir.children=" + Arrays.toString(FSRecords.listAll(myId)), e); + } LOG.assertTrue(!(getFileSystem() instanceof Win32LocalFileSystem)); VirtualFileSystemEntry child = VfsData.getFileById(id, this); diff --git a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java index 16ed50c905d2..77cceb507291 100644 --- a/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/vfs/newvfs/persistent/PersistentFSImpl.java @@ -908,14 +908,14 @@ public class PersistentFSImpl extends PersistentFS implements ApplicationCompone try { VfsData.initFile(rootId, segment, -1, directoryData); } - catch (AssertionError e) { + catch (VfsData.FileAlreadyCreatedException e) { for (Map.Entry entry : myRoots.entrySet()) { final VirtualFileSystemEntry existingRoot = entry.getValue(); if (Math.abs(existingRoot.getId()) == rootId) { throw new RuntimeException("Duplicate FS roots: " + rootUrl + " and " + entry.getKey() + ", id=" + rootId + ", valid=" + existingRoot.isValid(), e); } } - throw new RuntimeException("No root duplication, roots" + Arrays.toString(FSRecords.listAll(1)), e); + throw new RuntimeException("No root duplication, roots=" + Arrays.toString(FSRecords.listAll(1)), e); } incStructuralModificationCount(); mark = writeAttributesToRecord(rootId, 0, newRoot, fs, attributes);