This is an automated email from the ASF dual-hosted git repository.
tabish pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-protonj2.git
The following commit(s) were added to refs/heads/main by this push:
new 8b41608 PROTON-2454 Clear body when bodySections is called in all
cases
8b41608 is described below
commit 8b416088dbeada18f58a8573194cb86593f07562
Author: Timothy Bish <[email protected]>
AuthorDate: Tue Nov 2 18:55:08 2021 -0400
PROTON-2454 Clear body when bodySections is called in all cases
Adding a collection of body sections should clear any previous singular
or collection assigned value always.
---
.../qpid/protonj2/client/impl/ClientMessage.java | 3 ++-
.../qpid/protonj2/client/impl/ClientMessageTest.java | 18 ++++++++++++++++++
2 files changed, 20 insertions(+), 1 deletion(-)
diff --git
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientMessage.java
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientMessage.java
index 0bfc729..35b336e 100644
---
a/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientMessage.java
+++
b/protonj2-client/src/main/java/org/apache/qpid/protonj2/client/impl/ClientMessage.java
@@ -650,13 +650,14 @@ public class ClientMessage<E> implements
AdvancedMessage<E> {
public ClientMessage<E> bodySections(Collection<Section<?>> sections) {
if (sections == null || sections.isEmpty()) {
bodySections = null;
- body = null;
} else {
List<Section<?>> result = new ArrayList<>(sections.size());
sections.forEach(section ->
result.add(validateBodySections(messageFormat, result, section)));
bodySections = result;
}
+ body = null; // Body is always cleared by this assignment.
+
return this;
}
diff --git
a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ClientMessageTest.java
b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ClientMessageTest.java
index e1fee22..1a695b2 100644
---
a/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ClientMessageTest.java
+++
b/protonj2-client/src/test/java/org/apache/qpid/protonj2/client/impl/ClientMessageTest.java
@@ -534,6 +534,24 @@ class ClientMessageTest {
}
@Test
+ public void testReplaceOriginalWithSetBodySectionClearsOriginal() {
+ ClientMessage<Object> message = ClientMessage.create();
+
+ message.body("string"); // AmqpValue
+
+ List<Section<?>> expected = new ArrayList<>();
+ expected.add(new Data(new byte[] { 0 }));
+ expected.add(new Data(new byte[] { 1 }));
+
+ assertEquals("string", message.body());
+ assertEquals(1, message.bodySections().size());
+
+ message.bodySections(expected);
+
+ assertEquals(expected.size(), message.bodySections().size());
+ }
+
+ @Test
public void
testReplaceOriginalWithSetBodySectionDoesThrowValidationErrorIfInValid() {
ClientMessage<Object> message = ClientMessage.create();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]