You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@activemq.apache.org by "gt2001atgmail (via GitHub)" <gi...@apache.org> on 2026/09/13 05:56:57 UTC
[PR] fix: ActiveMQObjectMessage/ActiveMQMapMessage doGetBody() deserializes message body twice [activemq]
gt2001atgmail opened a new pull request, #2561:
URL: https://github.com/apache/activemq/pull/2561
doGetBody() in both classes re-deserializes the content directly instead of reusing the cache getObject()/getContentMap() already populate, so getBody() ends up deserializing twice. Fixed both to delegate to the cached getter, same as ActiveMQTextMessage already does. Added a test per class to catch the regression.
See: https://github.com/apache/activemq/issues/2516
--
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: gitbox-unsubscribe@activemq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact
Re: [PR] fix: ActiveMQObjectMessage/ActiveMQMapMessage doGetBody() deserializes message body twice [activemq]
Posted by "gt2001atgmail (via GitHub) via gitbox" <gi...@activemq.apache.org>.
gt2001atgmail commented on PR #2561:
URL: https://github.com/apache/activemq/pull/2561#issuecomment-6940071098
Thanks for testing this so thoroughly!
1. Good catch, removed. It only serialized once per `setObject()`, not on every call, but it was still unneeded.
2. Agreed, worth a release note.
Added your counting test too.
--
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: gitbox-unsubscribe@activemq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact
Re: [PR] fix: ActiveMQObjectMessage/ActiveMQMapMessage doGetBody() deserializes message body twice [activemq]
Posted by "lobtx (via GitHub) via gitbox" <gi...@activemq.apache.org>.
lobtx commented on PR #2561:
URL: https://github.com/apache/activemq/pull/2561#issuecomment-6802080719
Hi, I was about to open a PR for #2516 when I saw yours, so I reviewed and tested it instead.
I tested this PR merged with the current `main` (it merges cleanly) on JDK 21:
- the new tests pass, as well as `ActiveMQJMS2MessageTest`, `JMSMessageTest` and `ActiveMQJMS2ReceiveBodyTest` (103 tests)
- I also ran a test that counts the actual deserializations, using a `Serializable` with a `readObject()` that increments a counter, on a message that only has its serialized content (`storeContentAndClear()`): `getBody()` deserializes twice on `main` and once with this PR.
Two small remarks:
1. `ActiveMQObjectMessage.doGetBody()` still calls `storeContent()` before `getObject()`. On the producer side, after `setObject()`, this serializes the object on every `getBody()` call although the result is not used anymore. It could be removed, unless there is a reason to keep it.
2. Worth mentioning in the release notes maybe: `getBody()` now returns the same instance as `getObject()` / `getContentMap()` instead of a new copy. That looks fine to me since `getObject()` already returned the cached instance.
If it helps, the counting test (it checks the number of deserializations rather than the instance identity):
```java
public void testGetBodyDeserializesOnce() throws Exception {
ActiveMQObjectMessage msg = new ActiveMQObjectMessage();
msg.setObject(new CountingSerializable("test"));
// as on the consumer side: only the serialized content is available
msg.storeContentAndClear();
CountingSerializable.READ_COUNT.set(0);
CountingSerializable body = msg.getBody(CountingSerializable.class);
assertEquals("test", body.value);
assertEquals(1, CountingSerializable.READ_COUNT.get());
}
static class CountingSerializable implements Serializable {
private static final long serialVersionUID = 1L;
static final AtomicInteger READ_COUNT = new AtomicInteger();
final String value;
CountingSerializable(String value) {
this.value = value;
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject();
READ_COUNT.incrementAndGet();
}
}
```
LGTM otherwise.
--
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: gitbox-unsubscribe@activemq.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscribe@activemq.apache.org
For additional commands, e-mail: gitbox-help@activemq.apache.org
For further information, visit: https://activemq.apache.org/contact