You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by gw...@apache.org on 2016/04/12 01:10:04 UTC

[48/50] [abbrv] kafka git commit: MINOR: fix incorrect exception message in KafkaProducer

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 <ig...@keystonett.com>

Reviewers: Guozhang Wang <wa...@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 <ig...@keystonett.com>
Authored: Mon Apr 11 12:02:49 2016 -0700
Committer: Guozhang Wang <wa...@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,