mirror of https://github.com/apache/lucene.git
LUCENE-6152: Fix double close bug in OutputStreamIndexOutput
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1648724 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4a6d85790a
commit
2d422a995a
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue