Index: lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java =================================================================== --- lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java (revision 1160833) +++ lucene/src/java/org/apache/lucene/store/CompoundFileWriter.java (working copy) @@ -190,6 +190,7 @@ private final long copyFileEntry(IndexOutput dataOut, FileEntry fileEntry) throws IOException, MergeAbortedException { final IndexInput is = fileEntry.dir.openInput(fileEntry.file, IOContext.READONCE); + boolean success = false; try { final long startPtr = dataOut.getFilePointer(); final long length = fileEntry.length; @@ -201,11 +202,14 @@ throw new IOException("Difference in the output file offsets " + diff + " does not match the original file length " + length); fileEntry.offset = startPtr; - // copy successful - delete file - fileEntry.dir.deleteFile(fileEntry.file); + success = true; return length; } finally { - is.close(); + IOUtils.closeSafely(!success, is); + if (success) { + // copy successful - delete file + fileEntry.dir.deleteFile(fileEntry.file); + } } }