From cbead882735849ba7f6811467d5ffb99a2c99cf8 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Thu, 21 May 2015 21:24:04 +0200 Subject: [PATCH] Check engine reference for null before flushing If we close the shard before the engine is started we see a NPE in the logs which is not problematic since the relevant parts are in a finally block. Yet, the NPE is unnecessary and can be confusing. --- src/main/java/org/elasticsearch/index/shard/IndexShard.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/elasticsearch/index/shard/IndexShard.java b/src/main/java/org/elasticsearch/index/shard/IndexShard.java index e2ebf5579ba..71c0bc1347d 100644 --- a/src/main/java/org/elasticsearch/index/shard/IndexShard.java +++ b/src/main/java/org/elasticsearch/index/shard/IndexShard.java @@ -761,7 +761,7 @@ public class IndexShard extends AbstractIndexShardComponent { } finally { final Engine engine = this.currentEngineReference.getAndSet(null); try { - if (flushEngine && this.flushOnClose) { + if (engine != null && flushEngine && this.flushOnClose) { engine.flushAndClose(); } } finally { // playing safe here and close the engine even if the above succeeds - close can be called multiple times