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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to