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); } } }