Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DB74418357 for ; Fri, 31 Jul 2015 18:46:45 +0000 (UTC) Received: (qmail 42134 invoked by uid 500); 31 Jul 2015 18:46:45 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 42096 invoked by uid 500); 31 Jul 2015 18:46:45 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 42081 invoked by uid 99); 31 Jul 2015 18:46:45 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 Jul 2015 18:46:45 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9CDC0E03A7; Fri, 31 Jul 2015 18:46:45 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: cshannon@apache.org To: commits@activemq.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: activemq git commit: https://issues.apache.org/jira/browse/AMQ-5857 Date: Fri, 31 Jul 2015 18:46:45 +0000 (UTC) Repository: activemq Updated Branches: refs/heads/master ac3d08864 -> 310c2bb05 https://issues.apache.org/jira/browse/AMQ-5857 Fixing a potential race condition in the storeContent method of ActiveMQTextMessage Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/310c2bb0 Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/310c2bb0 Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/310c2bb0 Branch: refs/heads/master Commit: 310c2bb05916811a25b84d76f11fb84b40087914 Parents: ac3d088 Author: Christopher L. Shannon (cshannon) Authored: Fri Jul 31 18:27:12 2015 +0000 Committer: Christopher L. Shannon (cshannon) Committed: Fri Jul 31 18:32:02 2015 +0000 ---------------------------------------------------------------------- .../activemq/command/ActiveMQTextMessage.java | 31 ++++++++++---------- 1 file changed, 16 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/310c2bb0/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQTextMessage.java ---------------------------------------------------------------------- diff --git a/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQTextMessage.java b/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQTextMessage.java index cca09be..97fc9e4 100755 --- a/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQTextMessage.java +++ b/activemq-client/src/main/java/org/apache/activemq/command/ActiveMQTextMessage.java @@ -78,29 +78,28 @@ public class ActiveMQTextMessage extends ActiveMQMessage implements TextMessage @Override public String getText() throws JMSException { - if (text == null && getContent() != null) { - text = decodeContent(); + ByteSequence content = getContent(); + + if (text == null && content != null) { + text = decodeContent(content); setContent(null); setCompressed(false); } return text; } - private String decodeContent() throws JMSException { + private String decodeContent(ByteSequence bodyAsBytes) throws JMSException { String text = null; - if (getContent() != null) { + if (bodyAsBytes != null) { InputStream is = null; try { - ByteSequence bodyAsBytes = getContent(); - if (bodyAsBytes != null) { - is = new ByteArrayInputStream(bodyAsBytes); - if (isCompressed()) { - is = new InflaterInputStream(is); - } - DataInputStream dataIn = new DataInputStream(is); - text = MarshallingSupport.readUTF8(dataIn); - dataIn.close(); + is = new ByteArrayInputStream(bodyAsBytes); + if (isCompressed()) { + is = new InflaterInputStream(is); } + DataInputStream dataIn = new DataInputStream(is); + text = MarshallingSupport.readUTF8(dataIn); + dataIn.close(); } catch (IOException ioe) { throw JMSExceptionSupport.create(ioe); } finally { @@ -132,6 +131,7 @@ public class ActiveMQTextMessage extends ActiveMQMessage implements TextMessage public void storeContent() { try { ByteSequence content = getContent(); + String text = this.text; if (content == null && text != null) { ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); OutputStream os = bytesOut; @@ -141,7 +141,7 @@ public class ActiveMQTextMessage extends ActiveMQMessage implements TextMessage os = new DeflaterOutputStream(os); } DataOutputStream dataOut = new DataOutputStream(os); - MarshallingSupport.writeUTF8(dataOut, this.text); + MarshallingSupport.writeUTF8(dataOut, text); dataOut.close(); setContent(bytesOut.toByteSequence()); } @@ -177,6 +177,7 @@ public class ActiveMQTextMessage extends ActiveMQMessage implements TextMessage @Override public int getSize() { + String text = this.text; if (size == 0 && content == null && text != null) { size = getMinimumMessageSize(); if (marshalledProperties != null) { @@ -192,7 +193,7 @@ public class ActiveMQTextMessage extends ActiveMQMessage implements TextMessage try { String text = this.text; if( text == null ) { - text = decodeContent(); + text = decodeContent(getContent()); } if (text != null) { text = MarshallingSupport.truncate64(text);