Repository navigation
fix: ActiveMQObjectMessage/ActiveMQMapMessage doGetBody() deserializes message body twice - #2561
Open
gt2001atgmail wants to merge 2 commits into
Open
gt2001atgmail wants to merge 2 commits into
gt2001atgmail wants to merge 2 commits into
Conversation
…s message body twice 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: apache#2516
|
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
Two small remarks:
If it helps, the counting test (it checks the number of deserializations rather than the instance identity): 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. |
getObject() already handles it. Also add a deserialization-count test suggested in review.
Author
|
Thanks for testing this so thoroughly!
Added your counting test too. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: #2516