Fix exception being thrown when attempting to parse an ID that does not have an 
embedded ProducerSequenceId.
Fixes [AMQNET-492]. (See https://issues.apache.org/jira/browse/AMQNET-492)



Project: http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/commit/35d3fb6d
Tree: http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/tree/35d3fb6d
Diff: http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/diff/35d3fb6d

Branch: refs/heads/1.7.x
Commit: 35d3fb6d44764c7c39d5f284204a2c51b186cbd3
Parents: 7cabda2
Author: Jim Gomes <jgo...@apache.org>
Authored: Wed Jul 8 22:05:36 2015 +0000
Committer: Jim Gomes <jgo...@apache.org>
Committed: Wed Jul 8 22:05:36 2015 +0000

----------------------------------------------------------------------
 src/main/csharp/Commands/MessageId.cs | 73 ++++++++++++++----------------
 1 file changed, 35 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-nms-stomp/blob/35d3fb6d/src/main/csharp/Commands/MessageId.cs
----------------------------------------------------------------------
diff --git a/src/main/csharp/Commands/MessageId.cs 
b/src/main/csharp/Commands/MessageId.cs
index b559bc3..dd7e202 100644
--- a/src/main/csharp/Commands/MessageId.cs
+++ b/src/main/csharp/Commands/MessageId.cs
@@ -21,20 +21,19 @@ namespace Apache.NMS.Stomp.Commands
 {
     public class MessageId : BaseDataStructure
     {
-        ProducerId producerId;
-        long producerSequenceId;
-        long brokerSequenceId;
-
+        private ProducerId producerId;
+        private long producerSequenceId;
+        private long brokerSequenceId;
         private string key = null;
 
         public MessageId() : base()
         {
         }
 
-        public MessageId(ProducerId producerId, long producerSequenceId) : 
base()
+        public MessageId(ProducerId prodId, long producerSeqId) : base()
         {
-            this.producerId = producerId;
-            this.producerSequenceId = producerSequenceId;
+            this.producerId = prodId;
+            this.producerSequenceId = producerSeqId;
         }
 
         public MessageId(string value) : base()
@@ -61,12 +60,12 @@ namespace Apache.NMS.Stomp.Commands
         ///
         public override string ToString()
         {
-            if( key == null )
+            if(null == this.key)
             {
-                key = producerId.ToString() + ":" + producerSequenceId;
+                this.key = string.Format("{0}:{1}", 
this.producerId.ToString(), this.producerSequenceId);
             }
 
-            return key;
+            return this.key;
         }
 
         /// <summary>
@@ -74,33 +73,42 @@ namespace Apache.NMS.Stomp.Commands
         /// </summary>
         public void SetValue(string messageKey)
         {
-            this.key = messageKey;
+            string mkey = messageKey;
+
+            this.key = mkey;
 
             // Parse off the sequenceId
-            int p = messageKey.LastIndexOf(":");
+            int p = mkey.LastIndexOf(":");
             if(p >= 0)
             {
-                producerSequenceId = Int64.Parse(messageKey.Substring(p + 1));
-                messageKey = messageKey.Substring(0, p);
+                if(Int64.TryParse(mkey.Substring(p + 1), out 
this.producerSequenceId))
+                {
+                    mkey = mkey.Substring(0, p);
+                }
+                else
+                {
+                    this.producerSequenceId = 0;
+                }
             }
-            producerId = new ProducerId(messageKey);
+
+            producerId = new ProducerId(mkey);
         }
 
         public ProducerId ProducerId
         {
-            get { return producerId; }
+            get { return this.producerId; }
             set { this.producerId = value; }
         }
 
         public long ProducerSequenceId
         {
-            get { return producerSequenceId; }
+            get { return this.producerSequenceId; }
             set { this.producerSequenceId = value; }
         }
 
         public long BrokerSequenceId
         {
-            get { return brokerSequenceId; }
+            get { return this.brokerSequenceId; }
             set { this.brokerSequenceId = value; }
         }
 
@@ -108,9 +116,9 @@ namespace Apache.NMS.Stomp.Commands
         {
             int answer = 0;
 
-            answer = (answer * 37) + HashCode(ProducerId);
-            answer = (answer * 37) + HashCode(ProducerSequenceId);
-            answer = (answer * 37) + HashCode(BrokerSequenceId);
+            answer = (answer * 37) + HashCode(this.ProducerId);
+            answer = (answer * 37) + HashCode(this.ProducerSequenceId);
+            answer = (answer * 37) + HashCode(this.BrokerSequenceId);
 
             return answer;
         }
@@ -121,26 +129,15 @@ namespace Apache.NMS.Stomp.Commands
             {
                 return Equals((MessageId) that);
             }
+
             return false;
         }
 
         public virtual bool Equals(MessageId that)
         {
-            if(!Equals(this.ProducerId, that.ProducerId))
-            {
-                return false;
-            }
-            if(!Equals(this.ProducerSequenceId, that.ProducerSequenceId))
-            {
-                return false;
-            }
-            if(!Equals(this.BrokerSequenceId, that.BrokerSequenceId))
-            {
-                return false;
-            }
-
-            return true;
+            return (Equals(this.ProducerId, that.ProducerId)
+                    && Equals(this.ProducerSequenceId, that.ProducerSequenceId)
+                    && Equals(this.BrokerSequenceId, that.BrokerSequenceId));
         }
-    };
-}
-
+    }
+}
\ No newline at end of file

Reply via email to