Apache Solr open-source search software
LUCENE-6616: Lucene50SegmentInfoFormat should not claim to have created a file until the createOutput in fact succeeded
Michael McCandless3b0418c66e57
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoFormat.javaindex 1e362782b34..9fa3a095739 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoFormat.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoFormat.java@@ -123,9 +123,10 @@ public class Lucene50SegmentInfoFormat extends SegmentInfoFormat {@Overridepublic void write(Directory dir, SegmentInfo si, IOContext ioContext) throws IOException {final String fileName = IndexFileNames.segmentFileName(si.name, "", Lucene50SegmentInfoFormat.SI_EXTENSION);- si.addFile(fileName);try (IndexOutput output = dir.createOutput(fileName, ioContext)) {+ // Only add the file once we've successfully created it, else IFD assert can trip:+ si.addFile(fileName);CodecUtil.writeIndexHeader(output,Lucene50SegmentInfoFormat.CODEC_NAME,Lucene50SegmentInfoFormat.VERSION_CURRENT,diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java b/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.javaindex 2cb14cf86ba..c088700b794 100644--- a/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java+++ b/lucene/core/src/java/org/apache/lucene/index/IndexFileDeleter.java@@ -747,8 +747,8 @@ final class IndexFileDeleter implements Closeable {} catch (IOException e) { // if delete fails// IndexWriter should only ask us to delete files it knows it wrote, so if we hit this, something is wrong!- assert e instanceof NoSuchFileException == false: "file=" + fileName;- assert e instanceof FileNotFoundException == false: "file=" + fileName;+ assert e instanceof NoSuchFileException == false: "hit unexpected NoSuchFileException: file=" + fileName;+ assert e instanceof FileNotFoundException == false: "hit unexpected FileNotFoundException: file=" + fileName;// Some operating systems (e.g. Windows) don't// permit a file to be deleted while it is opened