ijuma commented on code in PR #12365:
URL: https://github.com/apache/kafka/pull/12365#discussion_r924189300


##########
clients/src/main/java/org/apache/kafka/clients/producer/KafkaProducer.java:
##########
@@ -1491,20 +1495,25 @@ public void setPartition(int partition) {
 
             if (log.isTraceEnabled()) {

Review Comment:
   For the line in this method, you could do something like:
   
   ```java
   if (partition < 0)
     throw new IllegalArgumentException("partition should be positive, but it 
was " + partition):
   ```
   
   Which is more informative and idiomatic and checks the more general case 
that we expect partitions to be positive. But I see that we have sprinkled the 
same check in other methods. So, having a `assertPartitionIsPositive` would 
probably be a better approach. In any case, since this code was introduced in a 
different change, we can file a JIRA and do it as a separate PR.
   
   I am happy to discuss more, but we should be clear about terminology. 
Language level asserts in Java aren't used much. Checking preconditions through 
API boundaries is useful. Within a given boundary, it's best to use the type 
system to avoid having noise all over the code.



-- 
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