Copilot commented on code in PR #10588:
URL: https://github.com/apache/rocketmq/pull/10588#discussion_r3518229893
##########
common/src/test/java/org/apache/rocketmq/common/MessageEncodeDecodeTest.java:
##########
@@ -72,4 +74,43 @@ public void testEncodeDecodeList() throws Exception {
}
}
+
+ @Test
+ public void testMessageBatchEncodePreservesInnerMessageUserProperty()
throws Exception {
+ List<Message> messages = new ArrayList<>(2);
+ for (int i = 0; i < 2; i++) {
+ Message message = new Message("topic", ("body" + i).getBytes());
+ message.putUserProperty("name", "value");
+ messages.add(message);
+ }
+ MessageBatch messageBatch = MessageBatch.generateFromList(messages);
+ messageBatch.putUserProperty("name", "value");
+
Review Comment:
`testMessageBatchEncodePreservesInnerMessageUserProperty` currently calls
`messageBatch.putUserProperty("name", "value")`, which (with this PR)
explicitly propagates the property onto inner messages. That makes the test
unable to verify the stated intent (that inner-message user properties survive
batch encode/decode without relying on batch-level propagation). Remove the
batch-level `putUserProperty` call so the test actually exercises preservation
of properties already present on inner messages.
##########
common/src/main/java/org/apache/rocketmq/common/message/MessageBatch.java:
##########
@@ -39,6 +39,14 @@ public Iterator<Message> iterator() {
return messages.iterator();
}
+ @Override
+ public void putUserProperty(String name, String value) {
+ super.putUserProperty(name, value);
+ for (Message message : messages) {
+ message.putUserProperty(name, value);
+ }
+ }
Review Comment:
`MessageBatch` has a public constructor that can be called with a null
`messages` list. This override will throw a `NullPointerException` when
iterating, which is harder to diagnose than an explicit guard. Consider adding
a null check before the loop (either no-op propagation when `messages` is null,
or a clearer exception) to make failure mode deterministic and easier to debug.
--
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]