From 419f3976c2c29f02b82fd4c376527cb562a5c7be Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Tue, 5 Jan 2016 09:41:58 -0500 Subject: [PATCH] Fix NPE in TestClusterService when waiting indefinitely When waiting indefinitely for a new cluster state in a test, TestClusterService#add will throw a NullPointerException if the timeout is null. Instead, TestClusterService#add should guard against a null timeout and not even attempt to add a notification for the timeout expiring. Note that the usage of null is the agreed upon contract for specifying an indefinite wait from ClusterStateObserver. --- .../elasticsearch/test/cluster/TestClusterService.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/framework/src/main/java/org/elasticsearch/test/cluster/TestClusterService.java b/test/framework/src/main/java/org/elasticsearch/test/cluster/TestClusterService.java index 6e17eae1be4..93327213bbc 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/cluster/TestClusterService.java +++ b/test/framework/src/main/java/org/elasticsearch/test/cluster/TestClusterService.java @@ -184,9 +184,11 @@ public class TestClusterService implements ClusterService { if (threadPool == null) { throw new UnsupportedOperationException("TestClusterService wasn't initialized with a thread pool"); } - NotifyTimeout notifyTimeout = new NotifyTimeout(listener, timeout); - notifyTimeout.future = threadPool.schedule(timeout, ThreadPool.Names.GENERIC, notifyTimeout); - onGoingTimeouts.add(notifyTimeout); + if (timeout != null) { + NotifyTimeout notifyTimeout = new NotifyTimeout(listener, timeout); + notifyTimeout.future = threadPool.schedule(timeout, ThreadPool.Names.GENERIC, notifyTimeout); + onGoingTimeouts.add(notifyTimeout); + } listeners.add(listener); listener.postAdded(); }