From 70e5a726aafac60d3d22da78f6b8b46d5b484fe6 Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Wed, 13 Feb 2019 16:13:14 -0700 Subject: [PATCH] Only flush Watcher's bulk processor if Watcher is enabled (#38803) When shutting down Watcher, the `bulkProcessor` is null if watcher has been disabled in the configuration. This protects the flush and close calls with a check for watcher enabled to avoid a NullPointerException Resolves #38798 --- .../main/java/org/elasticsearch/xpack/watcher/Watcher.java | 6 ++++-- .../org/elasticsearch/xpack/watcher/WatcherPluginTests.java | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java index 6648241d82a3b..1519085a3accd 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java @@ -669,10 +669,12 @@ public List> getContexts() { @Override public void close() throws IOException { - bulkProcessor.flush(); + if (enabled) { + bulkProcessor.flush(); + } IOUtils.closeWhileHandlingException(httpClient); try { - if (bulkProcessor.awaitClose(10, TimeUnit.SECONDS) == false) { + if (enabled && bulkProcessor.awaitClose(10, TimeUnit.SECONDS) == false) { logger.warn("failed to properly close watcher bulk processor"); } } catch (InterruptedException e) { diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java index b13b035304d7c..a4131889f84a0 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java @@ -81,6 +81,8 @@ public void testWatcherDisabledTests() throws Exception { // also no component creation if not enabled assertThat(watcher.createComponents(null, null, null, null, null, null, null, null, null), hasSize(0)); + + watcher.close(); } public void testThreadPoolSize() {