mirror of
https://github.com/apache/lucene.git
synced 2025-02-22 01:56:16 +00:00
ensure output is closed if finish throws exception
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1229937 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
7de1e259f1
commit
ba60b2f98a
@ -17,6 +17,7 @@ package org.apache.lucene.codecs.simpletext;
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
|
||||
@ -71,7 +72,17 @@ public class SimpleTextNormsConsumer extends PerDocConsumer {
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
if (writer != null) {
|
||||
writer.finish();
|
||||
boolean success = false;
|
||||
try {
|
||||
writer.finish();
|
||||
success = true;
|
||||
} finally {
|
||||
if (success) {
|
||||
IOUtils.close(writer);
|
||||
} else {
|
||||
IOUtils.closeWhileHandlingException(writer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,7 +192,7 @@ public class SimpleTextNormsConsumer extends PerDocConsumer {
|
||||
return writer;
|
||||
}
|
||||
|
||||
private static class NormsWriter {
|
||||
private static class NormsWriter implements Closeable{
|
||||
|
||||
private final IndexOutput output;
|
||||
private int numTotalDocs = 0;
|
||||
@ -253,12 +264,16 @@ public class SimpleTextNormsConsumer extends PerDocConsumer {
|
||||
}
|
||||
|
||||
public void abort() throws IOException {
|
||||
IOUtils.close(output);
|
||||
close();
|
||||
}
|
||||
|
||||
public void finish() throws IOException {
|
||||
finish(numTotalDocs);
|
||||
IOUtils.close(output);
|
||||
finish(numTotalDocs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
output.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user