mirror of https://github.com/apache/lucene.git
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:
parent
c189d0fb74
commit
e26cc9283b
|
@ -284,7 +284,15 @@ public final class MemoryPostingsFormat extends PostingsFormat {
|
||||||
private MemoryFieldsConsumer(SegmentWriteState state) throws IOException {
|
private MemoryFieldsConsumer(SegmentWriteState state) throws IOException {
|
||||||
final String fileName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, EXTENSION);
|
final String fileName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, EXTENSION);
|
||||||
out = state.directory.createOutput(fileName, state.context);
|
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;
|
this.state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue