Skip to content

Apache Lucene open-source search software

LUCENE-4070: assign output to member to prevent double opening on error

Simon Willnauera0493e557085
diff --git a/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java b/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java
index 8134b8cba47..a5e3d1cfb04 100644
--- a/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/store/CompoundFileWriter.java
@@ -118,16 +118,14 @@ final class CompoundFileWriter implements Closeable{
private synchronized IndexOutput getOutput() throws IOException {
if (dataOut == null) {
- IndexOutput dataOutput = null;
boolean success = false;
try {
- dataOutput = directory.createOutput(dataFileName, IOContext.DEFAULT);
- dataOutput.writeVInt(FORMAT_CURRENT);
- dataOut = dataOutput;
+ dataOut = directory.createOutput(dataFileName, IOContext.DEFAULT);
+ dataOut.writeVInt(FORMAT_CURRENT);
success = true;
} finally {
if (!success) {
- IOUtils.closeWhileHandlingException(dataOutput);
+ IOUtils.closeWhileHandlingException(dataOut);
}
}
}