kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From guozh...@apache.org
Subject kafka git commit: HOTFIX: fix npe in StreamsMetadataState when onChange has not been called
Date Wed, 28 Sep 2016 00:35:37 GMT
Repository: kafka
Updated Branches:
  refs/heads/0.10.1 dfdf2e6cc -> 65b85e6a4


HOTFIX: fix npe in StreamsMetadataState when onChange has not been called

If some StreamsMetadataState methods are called before the onChange method is called a NullPointerException
was being thrown. Added null check for cluster in isInitialized method

Author: Damian Guy <damian.guy@gmail.com>

Reviewers: Guozhang Wang <wangguoz@gmail.com>

Closes #1920 from dguy/fix-npe-streamsmetadata

(cherry picked from commit 0c25c73782e6e70b8f37e3dda2fa2a5b0b1c8c65)
Signed-off-by: Guozhang Wang <wangguoz@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/65b85e6a
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/65b85e6a
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/65b85e6a

Branch: refs/heads/0.10.1
Commit: 65b85e6a490a1f121071da735e2abfce807c87d1
Parents: dfdf2e6
Author: Damian Guy <damian.guy@gmail.com>
Authored: Tue Sep 27 17:35:24 2016 -0700
Committer: Guozhang Wang <wangguoz@gmail.com>
Committed: Tue Sep 27 17:35:33 2016 -0700

----------------------------------------------------------------------
 .../kafka/streams/processor/internals/StreamsMetadataState.java | 2 +-
 .../streams/processor/internals/StreamsMetadataStateTest.java   | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/65b85e6a/streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamsMetadataState.java
----------------------------------------------------------------------
diff --git a/streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamsMetadataState.java
b/streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamsMetadataState.java
index 6f9bea6..ccb2cda 100644
--- a/streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamsMetadataState.java
+++ b/streams/src/main/java/org/apache/kafka/streams/processor/internals/StreamsMetadataState.java
@@ -234,7 +234,7 @@ public class StreamsMetadataState {
     }
 
     private boolean isInitialized() {
-        return !clusterMetadata.topics().isEmpty();
+        return clusterMetadata != null && !clusterMetadata.topics().isEmpty();
     }
 
     private class SourceTopicsInfo {

http://git-wip-us.apache.org/repos/asf/kafka/blob/65b85e6a/streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsMetadataStateTest.java
----------------------------------------------------------------------
diff --git a/streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsMetadataStateTest.java
b/streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsMetadataStateTest.java
index 03280a8..411e02d 100644
--- a/streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsMetadataStateTest.java
+++ b/streams/src/test/java/org/apache/kafka/streams/processor/internals/StreamsMetadataStateTest.java
@@ -115,6 +115,11 @@ public class StreamsMetadataStateTest {
     }
 
     @Test
+    public void shouldNotThrowNPEWhenOnChangeNotCalled() throws Exception {
+        new StreamsMetadataState(builder).getAllMetadataForStore("store");
+    }
+
+    @Test
     public void shouldGetAllStreamInstances() throws Exception {
         final StreamsMetadata one = new StreamsMetadata(hostOne, Utils.mkSet("table-one",
"table-two", "merged-table"),
                 Utils.mkSet(topic1P0, topic2P1, topic4P0));


Mime
View raw message