Apache Lucene open-source search software
LUCENE-3892: close IndexOutput on exception
Michael McCandlesscda371db213c
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForFactory.java b/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForFactory.javaindex aae122e3b07..85ce187e6b7 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForFactory.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/pfor/ForFactory.java@@ -45,7 +45,17 @@ public final class ForFactory extends IntStreamFactory {@Overridepublic IntIndexOutput createOutput(Directory dir, String fileName, IOContext context) throws IOException {- return new ForIndexOutput(dir.createOutput(fileName, context), blockSize);+ boolean success = false;+ IndexOutput out = dir.createOutput(fileName, context);+ try {+ IntIndexOutput ret = new ForIndexOutput(out, blockSize);+ success = true;+ return ret;+ } finally {+ if (!success) {+ IOUtils.closeWhileHandlingException(out);+ }+ }}@Overridediff --git a/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForFactory.java b/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForFactory.javaindex 64341b4db0e..d6ae897e784 100644--- a/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForFactory.java+++ b/lucene/core/src/java/org/apache/lucene/codecs/pfor/PForFactory.java@@ -45,7 +45,17 @@ public final class PForFactory extends IntStreamFactory {@Overridepublic IntIndexOutput createOutput(Directory dir, String fileName, IOContext context) throws IOException {- return new PForIndexOutput(dir.createOutput(fileName, context), blockSize);+ boolean success = false;+ IndexOutput out = dir.createOutput(fileName, context);+ try {+ IntIndexOutput ret = new PForIndexOutput(out, blockSize);+ success = true;+ return ret;+ } finally {+ if (!success) {+ IOUtils.closeWhileHandlingException(out);+ }+ }}@Override