You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by si...@apache.org on 2012/01/11 10:12:09 UTC
svn commit: r1229937 -
/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextNormsConsumer.java
Author: simonw
Date: Wed Jan 11 09:12:09 2012
New Revision: 1229937
URL: http://svn.apache.org/viewvc?rev=1229937&view=rev
Log:
ensure output is closed if finish throws exception
Modified:
lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextNormsConsumer.java
Modified: lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextNormsConsumer.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextNormsConsumer.java?rev=1229937&r1=1229936&r2=1229937&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextNormsConsumer.java (original)
+++ lucene/dev/trunk/lucene/src/java/org/apache/lucene/codecs/simpletext/SimpleTextNormsConsumer.java Wed Jan 11 09:12:09 2012
@@ -17,6 +17,7 @@ package org.apache.lucene.codecs.simplet
* limitations under the License.
*/
+import java.io.Closeable;
import java.io.IOException;
import java.util.Set;
@@ -71,7 +72,17 @@ public class SimpleTextNormsConsumer ext
@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 ext
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 ext
}
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();
}
}