guozhangwang commented on a change in pull request #10525:
URL: https://github.com/apache/kafka/pull/10525#discussion_r800263685



##########
File path: 
clients/src/main/java/org/apache/kafka/clients/producer/KafkaProducer.java
##########
@@ -1305,10 +1305,16 @@ private ClusterResourceListeners 
configureClusterResourceListeners(Serializer<K>
      */
     private int partition(ProducerRecord<K, V> record, byte[] serializedKey, 
byte[] serializedValue, Cluster cluster) {
         Integer partition = record.partition();
-        return partition != null ?
-                partition :
-                partitioner.partition(
-                        record.topic(), record.key(), serializedKey, 
record.value(), serializedValue, cluster);
+        if (partition != null) {
+            return partition;
+        }
+
+        int customPartition = partitioner.partition(
+                record.topic(), record.key(), serializedKey, record.value(), 
serializedValue, cluster);
+        if (customPartition < 0) {
+            throw new IllegalArgumentException(String.format("Invalid 
partition: %d. Partition number should always be non-negative.", 
customPartition));

Review comment:
       Could you make the error message to be more specific? E.g. "Partitioner 
generated invalid partition: %d.." to differentiate that a partitioner is used.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to