yet more diagnostics for VfsData.initFile exceptions (IDEA-CR-4584, EA-70830)

This commit is contained in:
peter
2015-09-08 19:06:17 +02:00
parent 86779c3c97
commit 8d9abb37a6
3 changed files with 18 additions and 7 deletions
@@ -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);
}
@@ -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);
@@ -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<String, VirtualFileSystemEntry> 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);