kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gwens...@apache.org
Subject [48/50] [abbrv] kafka git commit: MINOR: fix incorrect exception message in KafkaProducer
Date Mon, 11 Apr 2016 23:10:04 GMT
MINOR: fix incorrect exception message in KafkaProducer

While playing with client got the next exception:
```java
java.lang.IllegalArgumentException: Invalid partition given with record: 1 is not in the range
[0...1].
```
It's obviously incorrect, so I've fixed it.

Author: Igor Stepanov <igor.stepanov@keystonett.com>

Reviewers: Guozhang Wang <wangguoz@gmail.com>

Closes #1210 from stepio/trunk


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

Branch: refs/heads/0.10.0
Commit: 1ec842a3ea9bbe414a5c59f90569fbc3348bdfb8
Parents: 411b04a
Author: Igor Stepanov <igor.stepanov@keystonett.com>
Authored: Mon Apr 11 12:02:49 2016 -0700
Committer: Guozhang Wang <wangguoz@gmail.com>
Committed: Mon Apr 11 12:02:49 2016 -0700

----------------------------------------------------------------------
 .../org/apache/kafka/clients/producer/KafkaProducer.java  | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/1ec842a3/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 6acc059..d60e28e 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
@@ -711,13 +711,11 @@ public class KafkaProducer<K, V> implements Producer<K, V>
{
         Integer partition = record.partition();
         if (partition != null) {
             List<PartitionInfo> partitions = cluster.partitionsForTopic(record.topic());
-            int numPartitions = partitions.size();
+            int lastPartition = partitions.size() - 1;
             // they have given us a partition, use it
-            if (partition < 0 || partition >= numPartitions)
-                throw new IllegalArgumentException("Invalid partition given with record:
" + partition
-                                                   + " is not in the range [0..."
-                                                   + numPartitions
-                                                   + "].");
+            if (partition < 0 || partition > lastPartition) {
+                throw new IllegalArgumentException(String.format("Invalid partition given
with record: %d is not in the range [0...%d].", partition, lastPartition));
+            }
             return partition;
         }
         return this.partitioner.partition(record.topic(), record.key(), serializedKey, record.value(),
serializedValue,


Mime
View raw message