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-5098; ProducerRecord should validate the topic name
Date Sat, 03 Jun 2017 09:40:56 GMT
Repository: kafka
Updated Branches:
  refs/heads/0.11.0 45b326d93 -> c4b6df975


KAFKA-5098; ProducerRecord should validate the topic name

Author: huxihx <huxi_2b@hotmail.com>

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

Closes #3223 from huxihx/KAFKA-5098_Does_not_check_topic_name_before_sending

(cherry picked from commit 941e2177c0cf57eff818192258300d256971a11e)
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/c4b6df97
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/c4b6df97
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/c4b6df97

Branch: refs/heads/0.11.0
Commit: c4b6df975d2738a42184f246df06581c4be1d540
Parents: 45b326d
Author: huxihx <huxi_2b@hotmail.com>
Authored: Sat Jun 3 10:35:44 2017 +0100
Committer: Ismael Juma <ismael@juma.me.uk>
Committed: Sat Jun 3 10:40:50 2017 +0100

----------------------------------------------------------------------
 .../org/apache/kafka/clients/producer/ProducerRecord.java   | 9 +++++++++
 1 file changed, 9 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/c4b6df97/clients/src/main/java/org/apache/kafka/clients/producer/ProducerRecord.java
----------------------------------------------------------------------
diff --git a/clients/src/main/java/org/apache/kafka/clients/producer/ProducerRecord.java b/clients/src/main/java/org/apache/kafka/clients/producer/ProducerRecord.java
index 85428e5..5cac3ac 100644
--- a/clients/src/main/java/org/apache/kafka/clients/producer/ProducerRecord.java
+++ b/clients/src/main/java/org/apache/kafka/clients/producer/ProducerRecord.java
@@ -16,9 +16,11 @@
  */
 package org.apache.kafka.clients.producer;
 
+import org.apache.kafka.common.errors.InvalidTopicException;
 import org.apache.kafka.common.header.Header;
 import org.apache.kafka.common.header.Headers;
 import org.apache.kafka.common.header.internals.RecordHeaders;
+import org.apache.kafka.common.internals.Topic;
 
 /**
  * A key/value pair to be sent to Kafka. This consists of a topic name to which the record
is being sent, an optional
@@ -62,10 +64,17 @@ public class ProducerRecord<K, V> {
      * @param key The key that will be included in the record
      * @param value The record contents
      * @param headers the headers that will be included in the record
+     * @throws IllegalArgumentException if the topic name is null or invalid
+     * @throws IllegalArgumentException if the partition or timestamp is negative
      */
     public ProducerRecord(String topic, Integer partition, Long timestamp, K key, V value,
Iterable<Header> headers) {
         if (topic == null)
             throw new IllegalArgumentException("Topic cannot be null.");
+        try {
+            Topic.validate(topic);
+        } catch (InvalidTopicException e) {
+            throw new IllegalArgumentException(e.getMessage());
+        }
         if (timestamp != null && timestamp < 0)
             throw new IllegalArgumentException(
                     String.format("Invalid timestamp: %d. Timestamp should always be non-negative
or null.", timestamp));


Mime
View raw message