LUCENE-2446: ensure we close file if we hit exception writing codec header

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1583565 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2014-04-01 08:21:57 +00:00
parent c189d0fb74
commit e26cc9283b
1 changed files with 9 additions and 1 deletions

View File

@ -284,7 +284,15 @@ public final class MemoryPostingsFormat extends PostingsFormat {
private MemoryFieldsConsumer(SegmentWriteState state) throws IOException {
final String fileName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, EXTENSION);
out = state.directory.createOutput(fileName, state.context);
CodecUtil.writeHeader(out, CODEC_NAME, VERSION_CURRENT);
boolean success = false;
try {
CodecUtil.writeHeader(out, CODEC_NAME, VERSION_CURRENT);
success = true;
} finally {
if (!success) {
IOUtils.closeWhileHandlingException(out);
}
}
this.state = state;
}