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 15:31:10 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk ce04b1435 -> 9836adc73


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


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

Branch: refs/heads/trunk
Commit: 9836adc732288924813927c4869ffb3908febba1
Parents: ce04b14
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 16:30:42 2017 +0100

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


http://git-wip-us.apache.org/repos/asf/kafka/blob/9836adc7/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/9836adc7/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 b06b415..3fa007a 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;
@@ -964,6 +965,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/9836adc7/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 dd62457..26f7588 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
@@ -464,4 +464,16 @@ public class KafkaProducerTest {
 
         EasyMock.verify(interceptors);
     }
+
+    @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