diff --git a/platform/util/src/com/intellij/util/io/ReadWriteDirectBufferWrapper.java b/platform/util/src/com/intellij/util/io/ReadWriteDirectBufferWrapper.java index 16e41c9b8c0e..eec87e80f661 100644 --- a/platform/util/src/com/intellij/util/io/ReadWriteDirectBufferWrapper.java +++ b/platform/util/src/com/intellij/util/io/ReadWriteDirectBufferWrapper.java @@ -56,13 +56,16 @@ public class ReadWriteDirectBufferWrapper extends DirectBufferWrapper { final RandomAccessFile myFile; FileContext(final File file) throws IOException { - myFile = FileUtilRt.doIOOperation(new FileUtilRt.RepeatableIOOperation() { + myFile = FileUtilRt.doIOOperation(new FileUtilRt.RepeatableIOOperation() { @Nullable @Override - public RandomAccessFile execute(boolean finalAttempt) throws FileNotFoundException { + public RandomAccessFile execute(boolean finalAttempt) throws IOException { try { return new RandomAccessFile(file, RW); } catch (FileNotFoundException ex) { + if (!file.getParentFile().exists()) { + throw new IOException("Parent file doesn't exist:" + file); + } if (!finalAttempt) return null; throw ex; } @@ -91,12 +94,14 @@ public class ReadWriteDirectBufferWrapper extends DirectBufferWrapper { try { if (fileContext == null) fileContext = new FileContext(myFile); - final FileChannel channel = fileContext.myFile.getChannel(); + if (fileContext.myFile != null) { + final FileChannel channel = fileContext.myFile.getChannel(); - channel.position(myPosition); - buffer.rewind(); - channel.write(buffer); - myDirty = false; + channel.position(myPosition); + buffer.rewind(); + channel.write(buffer); + myDirty = false; + } } catch (IOException e) { LOG.error(e); @@ -109,7 +114,10 @@ public class ReadWriteDirectBufferWrapper extends DirectBufferWrapper { final ByteBuffer buffer = getCachedBuffer(); if (buffer == null || !isDirty()) return; - //noinspection SSBasedInspection - doFlush(null, buffer).dispose(); + Disposable disposable = doFlush(null, buffer); + if (disposable != null) { + //noinspection SSBasedInspection + disposable.dispose(); + } } } diff --git a/platform/util/src/com/intellij/util/io/ResizeableMappedFile.java b/platform/util/src/com/intellij/util/io/ResizeableMappedFile.java index e06019398051..a30e7f57e7c0 100644 --- a/platform/util/src/com/intellij/util/io/ResizeableMappedFile.java +++ b/platform/util/src/com/intellij/util/io/ResizeableMappedFile.java @@ -125,13 +125,16 @@ public class ResizeableMappedFile implements Forceable { final File lengthFile = getLengthFile(); DataOutputStream stream = null; try { - stream = FileUtilRt.doIOOperation(new FileUtilRt.RepeatableIOOperation() { + stream = FileUtilRt.doIOOperation(new FileUtilRt.RepeatableIOOperation() { @Nullable @Override - public DataOutputStream execute(boolean lastAttempt) throws FileNotFoundException { + public DataOutputStream execute(boolean lastAttempt) throws IOException { try { return new DataOutputStream(new FileOutputStream(lengthFile)); } catch (FileNotFoundException ex) { + if (!lengthFile.getParentFile().exists()) { + throw new IOException("Parent file doesn't exist:" + lengthFile); + } if (!lastAttempt) return null; throw ex; }