kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ij...@apache.org
Subject kafka git commit: KAFKA-2105; Check for null in KafkaProducer.partitionsFor
Date Thu, 31 Aug 2017 17:32:33 GMT
Repository: kafka
Updated Branches:
  refs/heads/0.11.0 9f3468645 -> c3980a22b


KAFKA-2105; Check for null in KafkaProducer.partitionsFor

Author: Manikumar Reddy <manikumar.reddy@gmail.com>

Reviewers: Ismael Juma <ismael@juma.me.uk>

Closes #3697 from omkreddy/KAFKA-2105

(cherry picked from commit 9836adc732288924813927c4869ffb3908febba1)
Signed-off-by: Ismael Juma <ismael@juma.me.uk>


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

Branch: refs/heads/0.11.0
Commit: c3980a22bdbe9f7477b6b56c4194f5c46d0307f9
Parents: 9f34686
Author: Manikumar Reddy <manikumar.reddy@gmail.com>
Authored: Thu Aug 31 16:30:33 2017 +0100
Committer: Ismael Juma <ismael@juma.me.uk>
Committed: Thu Aug 31 18:31:03 2017 +0100

----------------------------------------------------------------------
 .../src/main/java/org/apache/kafka/clients/Metadata.java |  1 +
 .../org/apache/kafka/clients/producer/KafkaProducer.java |  2 ++
 .../apache/kafka/clients/producer/KafkaProducerTest.java | 11 +++++++++++
 3 files changed, 14 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/c3980a22/clients/src/main/java/org/apache/kafka/clients/Metadata.java
----------------------------------------------------------------------
diff --git a/clients/src/main/java/org/apache/kafka/clients/Metadata.java b/clients/src/main/java/org/apache/kafka/clients/Metadata.java
index 0963bad..b4521c3 100644
--- a/clients/src/main/java/org/apache/kafka/clients/Metadata.java
+++ b/clients/src/main/java/org/apache/kafka/clients/Metadata.java
@@ -112,6 +112,7 @@ public final class Metadata {
      * will be reset on the next update.
      */
     public synchronized void add(String topic) {
+        Objects.requireNonNull(topic, "topic cannot be null");
         if (topics.put(topic, TOPIC_EXPIRY_NEEDS_UPDATE) == null) {
             requestUpdateForNewTopics();
         }

http://git-wip-us.apache.org/repos/asf/kafka/blob/c3980a22/clients/src/main/java/org/apache/kafka/clients/producer/KafkaProducer.java
----------------------------------------------------------------------
diff --git a/clients/src/main/java/org/apache/kafka/clients/producer/KafkaProducer.java b/clients/src/main/java/org/apache/kafka/clients/producer/KafkaProducer.java
index f9c5538..7690cac 100644
--- a/clients/src/main/java/org/apache/kafka/clients/producer/KafkaProducer.java
+++ b/clients/src/main/java/org/apache/kafka/clients/producer/KafkaProducer.java
@@ -66,6 +66,7 @@ import java.net.InetSocketAddress;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Properties;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
@@ -956,6 +957,7 @@ public class KafkaProducer<K, V> implements Producer<K, V>
{
      */
     @Override
     public List<PartitionInfo> partitionsFor(String topic) {
+        Objects.requireNonNull(topic, "topic cannot be null");
         try {
             return waitOnMetadata(topic, null, maxBlockTimeMs).cluster.partitionsForTopic(topic);
         } catch (InterruptedException e) {

http://git-wip-us.apache.org/repos/asf/kafka/blob/c3980a22/clients/src/test/java/org/apache/kafka/clients/producer/KafkaProducerTest.java
----------------------------------------------------------------------
diff --git a/clients/src/test/java/org/apache/kafka/clients/producer/KafkaProducerTest.java
b/clients/src/test/java/org/apache/kafka/clients/producer/KafkaProducerTest.java
index 56c1b18..46dcf14 100644
--- a/clients/src/test/java/org/apache/kafka/clients/producer/KafkaProducerTest.java
+++ b/clients/src/test/java/org/apache/kafka/clients/producer/KafkaProducerTest.java
@@ -473,4 +473,15 @@ public class KafkaProducerTest {
         
     }
 
+    @Test
+    public void testPartitionsForWithNullTopic() {
+        Properties props = new Properties();
+        props.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9000");
+        try (KafkaProducer<byte[], byte[]> producer = new KafkaProducer<>(props,
new ByteArraySerializer(), new ByteArraySerializer())) {
+            producer.partitionsFor(null);
+            fail("Expected NullPointerException to be raised");
+        } catch (NullPointerException e) {
+            // expected
+        }
+    }
 }


Mime
View raw message