From 20e84d63e045d3d26627e204c808677a8fe77dc4 Mon Sep 17 00:00:00 2001 From: "Christopher L. Shannon (cshannon)" Date: Mon, 11 Apr 2016 12:31:57 +0000 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-6142 Moving the bytes copy to the parent Message class to solve this this issue for all message types as that is the root cause (cherry picked from commit e69c2cbad6611fa355bd9eb592f03bd3b8f90abb) --- .../apache/activemq/command/ActiveMQBytesMessage.java | 2 -- .../java/org/apache/activemq/command/Message.java | 11 +++++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQBytesMessage.java b/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQBytesMessage.java index 5d618ac94b..8806028342 100755 --- a/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQBytesMessage.java +++ b/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQBytesMessage.java @@ -890,8 +890,6 @@ public class ActiveMQBytesMessage extends ActiveMQMessage implements BytesMessag Inflater inflater = new Inflater(); ByteArrayOutputStream decompressed = new ByteArrayOutputStream(); try { - //copy to prevent a race condition - AMQ-6142 - dataSequence = new ByteSequence(dataSequence.getData(), dataSequence.getOffset(), dataSequence.getLength()); length = ByteSequenceData.readIntBig(dataSequence); dataSequence.offset = 0; byte[] data = Arrays.copyOfRange(dataSequence.getData(), 4, dataSequence.getLength()); diff --git a/activemq-client/src/main/java/org/apache/activemq/command/Message.java b/activemq-client/src/main/java/org/apache/activemq/command/Message.java index 4c57feb7c8..f13db20e18 100755 --- a/activemq-client/src/main/java/org/apache/activemq/command/Message.java +++ b/activemq-client/src/main/java/org/apache/activemq/command/Message.java @@ -142,8 +142,8 @@ public abstract class Message extends BaseCommand implements MarshallAware, Mess copy.properties = properties; } - copy.content = content; - copy.marshalledProperties = marshalledProperties; + copy.content = copyByteSequence(content); + copy.marshalledProperties = copyByteSequence(marshalledProperties); copy.dataStructure = dataStructure; copy.readOnlyProperties = readOnlyProperties; copy.readOnlyBody = readOnlyBody; @@ -164,6 +164,13 @@ public abstract class Message extends BaseCommand implements MarshallAware, Mess // copy.referenceCount = referenceCount; } + private ByteSequence copyByteSequence(ByteSequence content) { + if (content != null) { + return new ByteSequence(content.getData(), content.getOffset(), content.getLength()); + } + return null; + } + public Object getProperty(String name) throws IOException { if (properties == null) { if (marshalledProperties == null) {