From 4f16c3dfd19c4d31e629f183478f0ec37c1eb08c Mon Sep 17 00:00:00 2001 From: "R. Tyler Croy" Date: Mon, 26 Jan 2015 06:20:46 -0800 Subject: [PATCH] Avoid NPEs when starting up and scanning brokers The problem was we were trying to parse the JSON of /brokers/ids' when the treecache found that node. Fixes #8 --- .../lookout/verspaetung/zk/BrokerTreeWatcher.groovy | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/groovy/com/github/lookout/verspaetung/zk/BrokerTreeWatcher.groovy b/src/main/groovy/com/github/lookout/verspaetung/zk/BrokerTreeWatcher.groovy index 32fa290..477aad9 100644 --- a/src/main/groovy/com/github/lookout/verspaetung/zk/BrokerTreeWatcher.groovy +++ b/src/main/groovy/com/github/lookout/verspaetung/zk/BrokerTreeWatcher.groovy @@ -68,9 +68,15 @@ class BrokerTreeWatcher implements TreeCacheListener { } ChildData nodeData = event.data + Integer brokerId = brokerIdFromPath(nodeData.path) + + if (brokerId == INVALID_BROKER_ID) { + return + } + Object brokerData = json.parseText(new String(nodeData.data, 'UTF-8')) - this.brokers << new KafkaBroker(brokerData, brokerIdFromPath(nodeData.path)) + this.brokers << new KafkaBroker(brokerData, brokerId) } /**