From 3591da6ff89019b31bba40bcc642858ae7c7dbfc Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Tue, 5 Mar 2019 10:11:18 -0500 Subject: [PATCH] Simplify FrozenEngine#getReader (#39539) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We really don’t need a try/finally in this method. --- .../index/engine/FrozenEngine.java | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/index/engine/FrozenEngine.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/index/engine/FrozenEngine.java index 9543e1a2a04..e9b57e316cc 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/index/engine/FrozenEngine.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/index/engine/FrozenEngine.java @@ -186,20 +186,11 @@ public final class FrozenEngine extends ReadOnlyEngine { } @SuppressForbidden(reason = "we manage references explicitly here") - private synchronized DirectoryReader getReader() throws IOException { - DirectoryReader reader = null; - boolean success = false; - try { - if (lastOpenedReader != null && lastOpenedReader.tryIncRef()) { - reader = lastOpenedReader; - } - success = true; - return reader; - } finally { - if (success == false) { - IOUtils.close(reader); - } + private synchronized DirectoryReader getReader() { + if (lastOpenedReader != null && lastOpenedReader.tryIncRef()) { + return lastOpenedReader; } + return null; } @Override