Pankraz76 commented on code in PR #21149:
URL: https://github.com/apache/kafka/pull/21149#discussion_r2671733798
##########
clients/src/main/java/org/apache/kafka/clients/producer/RoundRobinPartitioner.java:
##########
@@ -64,7 +64,11 @@ public int partition(String topic, Object key, byte[]
keyBytes, Object value, by
}
private int nextValue(String topic) {
- AtomicInteger counter = topicCounterMap.computeIfAbsent(topic, k ->
new AtomicInteger(0));
+ AtomicInteger counter = topicCounterMap.get(topic);
+ if(counter == null) {
+ counter = new AtomicInteger(0);
+ AtomicInteger counter = topicCounterMap.putIfAbsent(topic,
counter);
+ }
return counter.getAndIncrement();
}
Review Comment:
Yes, the only remaining effort would be to avoid the unused coupling by
referencing it explicitly, without any technical reason to do so.
Unfortunately, this is often considered best practice, since people tend to
clean up their code only superficially and leave the first working version
without further refinement—until it eventually reaches a state where it’s no
longer refactorable. As stated in the suggested change, to inline the code to
improve cohesion instead of coupling.
This is somewhat similar to an anti-pattern (e.g.,
[[DirectReturn](https://error-prone.picnic.tech/bugpatterns/DirectReturn/)](https://error-prone.picnic.tech/bugpatterns/DirectReturn/)).
That said, this is really just a side quest.
--
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]