From e26cc9283bfa0935115b5a1b81b1c9ae969914aa Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Tue, 1 Apr 2014 08:21:57 +0000 Subject: [PATCH] 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 --- .../lucene/codecs/memory/MemoryPostingsFormat.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.java b/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.java index b2a742ce5e6..4cf947d1b88 100644 --- a/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.java +++ b/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.java @@ -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; }