tabish121 commented on code in PR #979:
URL: https://github.com/apache/activemq/pull/979#discussion_r1108626647
##########
activemq-client/src/main/java/org/apache/activemq/command/ActiveMQBytesMessage.java:
##########
@@ -956,4 +956,22 @@ protected void doCompress() throws IOException {
}
}
}
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public boolean isBodyAssignableTo(Class c) {
+ return getContent() == null || c.isAssignableFrom(byte[].class);
+ }
+
+ @SuppressWarnings("unchecked")
+ protected <T> T doGetBody(Class<T> asType) {
+ //Make sure the bytes are stored before trying to copy and return
+ if (dataOut != null && getContent() == null) {
+ storeContent();
+ }
+
+ final ByteSequence content = getContent();
+ return content != null ? (T) new ByteSequence(content.getData(),
content.getOffset(),
+ content.getLength()).getData() : null;
Review Comment:
This isn't a deep copy from what I see in the ByteSequence code, just a
shallow wrapping of the array, plus it creates a new ByteSequence that would
never actually be used so needless GC. I'd just do an Arrays.copyOfRange on
the data in the original since you want t deep copy here to avoid the caller
modifying the bytes in the message content as you want to get the same payload
on a rollback / recover etc.
--
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]