activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cshan...@apache.org
Subject activemq git commit: https://issues.apache.org/jira/browse/AMQ-5857
Date Fri, 31 Jul 2015 18:46:45 GMT
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) <christopher.l.shannon@gmail.com>
Authored: Fri Jul 31 18:27:12 2015 +0000
Committer: Christopher L. Shannon (cshannon) <christopher.l.shannon@gmail.com>
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);


Mime
View raw message