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) {