Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-6152: Fix double close bug in OutputStreamIndexOutput

Uwe Schindler2d422a995af8
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index 45e07fa05b9..4c98a160804 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -400,6 +400,9 @@ Bug Fixes
* LUCENE-6124: Fix double-close() problems in codec and store APIs.
(Robert Muir)
+* LUCENE-6152: Fix double close problems in OutputStreamIndexOutput.
+ (Uwe Schindler)
+
Documentation
* LUCENE-5392: Add/improve analysis package documentation to reflect
diff --git a/lucene/core/src/java/org/apache/lucene/store/OutputStreamIndexOutput.java b/lucene/core/src/java/org/apache/lucene/store/OutputStreamIndexOutput.java
index 0edadbe3469..f13dd2b8e3a 100644
--- a/lucene/core/src/java/org/apache/lucene/store/OutputStreamIndexOutput.java
+++ b/lucene/core/src/java/org/apache/lucene/store/OutputStreamIndexOutput.java
@@ -30,6 +30,7 @@ public class OutputStreamIndexOutput extends IndexOutput {
private final BufferedOutputStream os;
private long bytesWritten = 0L;
+ private boolean flushedOnClose = false;
/**
* Creates a new {@link OutputStreamIndexOutput} with the given buffer size.
@@ -58,9 +59,14 @@ public class OutputStreamIndexOutput extends IndexOutput {
try (final OutputStream o = os) {
// We want to make sure that os.flush() was running before close:
// BufferedOutputStream may ignore IOExceptions while flushing on close().
- // TODO: this is no longer an issue in Java 8:
- // http://hg.openjdk.java.net/jdk8/tl/jdk/rev/759aa847dcaf
- o.flush();
+ // We keep this also in Java 8, although it claims to be fixed there,
+ // because there are more bugs around this! See:
+ // # https://bugs.openjdk.java.net/browse/JDK-7015589
+ // # https://bugs.openjdk.java.net/browse/JDK-8054565
+ if (!flushedOnClose) {
+ flushedOnClose = true; // set this BEFORE calling flush!
+ o.flush();
+ }
}
}