From 30e370966937f975ad0e3be8fb826c2c404ae4b2 Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Thu, 29 Mar 2018 14:53:45 +0300 Subject: [PATCH] FailureDetector: check that states is not null before use When a node is part of a cluster but is down (like in the situation where a cluster is taken down and up again but not all nodes are up). There is no application_state information for that node. This patch check that the information exists before using it to prevent null pointer exception. After this patch, a call to nodetool gossipinfo would return the available information without failing. See scylladb/scylla#3330 Signed-off-by: Amnon Heiman Message-Id: <20180329115345.29357-1-amnon@scylladb.com> (cherry picked from commit 4e4589ba6f88ebac2916d8da0521a8677f4e3b7b) --- .../java/org/apache/cassandra/gms/FailureDetector.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/apache/cassandra/gms/FailureDetector.java b/src/main/java/org/apache/cassandra/gms/FailureDetector.java index 9d6520c..8d6056f 100644 --- a/src/main/java/org/apache/cassandra/gms/FailureDetector.java +++ b/src/main/java/org/apache/cassandra/gms/FailureDetector.java @@ -105,9 +105,11 @@ public class FailureDetector extends APIMBean implements FailureDetectorMBean { ep.setAliave(obj.getBoolean("is_alive")); ep.setUpdateTimestamp(obj.getJsonNumber("update_time").longValue()); JsonArray states = obj.getJsonArray("application_state"); - for (int j = 0; j < states.size(); j++) { - JsonObject state = states.getJsonObject(j); - ep.addApplicationState(state.getInt("application_state"), state.getString("value")); + if (states != null) { + for (int j = 0; j < states.size(); j++) { + JsonObject state = states.getJsonObject(j); + ep.addApplicationState(state.getInt("application_state"), state.getString("value")); + } } res.put(obj.getString("addrs"), ep); }