From 893797be7ec29466d675c5d98e55c8d25b72343c Mon Sep 17 00:00:00 2001 From: Till Seeberger Date: Wed, 8 Jan 2020 12:00:16 +0100 Subject: [PATCH] fix NPE --- .../shell/ContextSubscribeCommand.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/hivemq/cli/commands/shell/ContextSubscribeCommand.java b/src/main/java/com/hivemq/cli/commands/shell/ContextSubscribeCommand.java index 9af349358..f1aa37831 100644 --- a/src/main/java/com/hivemq/cli/commands/shell/ContextSubscribeCommand.java +++ b/src/main/java/com/hivemq/cli/commands/shell/ContextSubscribeCommand.java @@ -133,13 +133,10 @@ private void stay() throws InterruptedException { latch.countDown(); }; - final Runnable waitForExitCommandRunnable = new Runnable() { - @Override - public void run() { - final Scanner scanner = new Scanner(System.in); - scanner.nextLine(); - latch.countDown(); - } + final Runnable waitForExitCommandRunnable = () -> { + final Scanner scanner = new Scanner(System.in); + scanner.nextLine(); + latch.countDown(); }; final ExecutorService WORKER_THREADS = Executors.newFixedThreadPool(2); @@ -151,19 +148,22 @@ public void run() { WORKER_THREADS.shutdownNow(); - if (!contextClient.getState().isConnectedOrReconnect()) { - removeContext(); - } - else { - mqttClientExecutor.unsubscribe(contextClient, this); + if (contextClient != null) { + if (!contextClient.getState().isConnectedOrReconnect()) { + removeContext(); + } + else { + mqttClientExecutor.unsubscribe(contextClient, this); + } } + } @Override public String toString() { return getClass().getSimpleName() + "{" + - "key=" + getKey() + + "key=" + ((contextClient == null)? "null" : getKey()) + ", topics=" + Arrays.toString(topics) + ", qos=" + Arrays.toString(qos) + ", outputToConsole=" + printToSTDOUT +