chia7712 commented on code in PR #21726:
URL: https://github.com/apache/kafka/pull/21726#discussion_r2958336029


##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/Fetch.java:
##########
@@ -47,9 +44,9 @@ public static <K, V> Fetch<K, V> forPartition(
             OffsetAndMetadata nextOffsetAndMetadata
     ) {
         Map<TopicPartition, List<ConsumerRecord<K, V>>> recordsMap = 
records.isEmpty()
-                ? new HashMap<>()
-                : mkMap(mkEntry(partition, records));
-        Map<TopicPartition, OffsetAndMetadata> nextOffsetAndMetadataMap = 
mkMap(mkEntry(partition, nextOffsetAndMetadata));
+                ? Map.of()
+                : Map.of(partition, records);
+        Map<TopicPartition, OffsetAndMetadata> nextOffsetAndMetadataMap = 
Map.of(partition, nextOffsetAndMetadata);

Review Comment:
   It seems we always create Fetch via Fetch.empty(), which returns a mutable 
map internally. The Fetch created with an immutable map is only used as the 
source to be added. Therefore, we are lucky not to encounter an 
UnsupportedOperationException
   
   At any rate, we need to fix this error-prone code. We will file a minor 
patch.



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