cmccabe commented on a change in pull request #8640:
URL: https://github.com/apache/kafka/pull/8640#discussion_r436401514
##########
File path:
clients/src/test/java/org/apache/kafka/common/message/MessageTest.java
##########
@@ -962,4 +962,23 @@ private void verifyWriteSucceeds(short version, Message
message) throws Exceptio
assertEquals("Expected the serialized size to be " + size +
", but it was " + buf.position(), size, buf.position());
}
+
+ @Test
+ public void testCompareWithUnknownTaggedFields() throws Exception {
+ CreateTopicsRequestData createTopics = new CreateTopicsRequestData();
+ createTopics.setTimeoutMs(123);
+ CreateTopicsRequestData createTopics2 = new CreateTopicsRequestData();
+ createTopics2.setTimeoutMs(123);
+ assertEquals(createTopics, createTopics2);
+ assertEquals(createTopics2, createTopics);
+ createTopics.unknownTaggedFields();
+ assertEquals(createTopics, createTopics2);
+ assertEquals(createTopics2, createTopics);
Review comment:
No, this is intentional. Invoking `unknownTaggedFields` will create the
list if it doesn't exist. There is an optimization where if the list is empty,
as it will be the vast majority of the time, we just store null. Example:
```
@Override
public List<RawTaggedField> unknownTaggedFields() {
if (_unknownTaggedFields == null) {
_unknownTaggedFields = new ArrayList<>(0);
}
return _unknownTaggedFields;
}
```
Therefore it is good to test that messages with null here are equivalent
(via `equals`) to messages that have an empty list here.
----------------------------------------------------------------
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:
[email protected]