ijuma commented on a change in pull request #9714: URL: https://github.com/apache/kafka/pull/9714#discussion_r539020882
########## File path: clients/src/main/java/org/apache/kafka/common/requests/RequestUtils.java ########## @@ -76,36 +75,22 @@ public static boolean hasTransactionalRecords(ProduceRequest request) { return new AbstractMap.SimpleEntry<>(hasIdempotentRecords, hasTransactionalRecords); } - public static MessageSizeAccumulator size( - ObjectSerializationCache serializationCache, - Message header, - short headerVersion, - Message apiMessage, - short apiVersion - ) { - MessageSizeAccumulator messageSize = new MessageSizeAccumulator(); - if (header != null) - header.addSize(messageSize, serializationCache, headerVersion); - apiMessage.addSize(messageSize, serializationCache, apiVersion); - return messageSize; - } - public static ByteBuffer serialize( Message header, short headerVersion, Message apiMessage, short apiVersion ) { - ObjectSerializationCache serializationCache = new ObjectSerializationCache(); - MessageSizeAccumulator messageSize = RequestUtils.size(serializationCache, header, headerVersion, apiMessage, apiVersion); + ObjectSerializationCache cache = new ObjectSerializationCache(); + + int headerSize = header.size(cache, headerVersion); + int messageSize = apiMessage.size(cache, apiVersion); + ByteBufferAccessor writable = new ByteBufferAccessor(ByteBuffer.allocate(4 + headerSize + messageSize)); Review comment: Great catch. This was a copy and paste bug and we had no tests verifying this. I have fixed it and added a test. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org