diff --git a/src/main/java/org/elasticsearch/common/compress/CompressedDirectory.java b/src/main/java/org/elasticsearch/common/compress/CompressedDirectory.java index e5a6b2d0cd5..11a6b9897e1 100644 --- a/src/main/java/org/elasticsearch/common/compress/CompressedDirectory.java +++ b/src/main/java/org/elasticsearch/common/compress/CompressedDirectory.java @@ -3,6 +3,7 @@ package org.elasticsearch.common.compress; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import org.apache.lucene.store.*; +import org.apache.lucene.util.IOUtils; import org.elasticsearch.index.store.support.ForceSyncDirectory; import java.io.IOException; @@ -77,8 +78,8 @@ public class CompressedDirectory extends Directory implements ForceSyncDirectory IndexInput in = openInput(name, IOContext.READONCE); try { return in.length(); - } catch (Exception e) { - in.close(); + } finally { + IOUtils.close(in); } } return dir.fileLength(name);