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

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1340514 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Simon Willnauer 2012-05-19 16:29:58 +00:00
parent 5efed3447e
commit a0493e5570
1 changed files with 3 additions and 5 deletions

View File

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