rocketmq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ding...@apache.org
Subject [rocketmq] branch develop updated: [ISSUE #1463] Skip encode the null value property as string "null" (#1899)
Date Fri, 03 Apr 2020 08:20:16 GMT
This is an automated email from the ASF dual-hosted git repository.

dinglei pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/rocketmq.git


The following commit(s) were added to refs/heads/develop by this push:
     new 7760bb4  [ISSUE #1463] Skip encode the null value property as string "null" (#1899)
7760bb4 is described below

commit 7760bb4a43924608cb998fc87d038c9cf472fcd1
Author: carlvine500 <carlvine500@163.com>
AuthorDate: Fri Apr 3 16:20:08 2020 +0800

    [ISSUE #1463] Skip encode the null value property as string "null" (#1899)
    
    * Update MessageDecoder.java
    * add test case for MessageDecoder
---
 .../rocketmq/common/message/MessageDecoder.java     |  3 +++
 .../rocketmq/common/message/MessageDecoderTest.java | 21 ++++++++++++++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)

diff --git a/common/src/main/java/org/apache/rocketmq/common/message/MessageDecoder.java b/common/src/main/java/org/apache/rocketmq/common/message/MessageDecoder.java
index 54d5e6b..d048dde 100644
--- a/common/src/main/java/org/apache/rocketmq/common/message/MessageDecoder.java
+++ b/common/src/main/java/org/apache/rocketmq/common/message/MessageDecoder.java
@@ -414,6 +414,9 @@ public class MessageDecoder {
                 final String name = entry.getKey();
                 final String value = entry.getValue();
 
+                if (value == null) {
+                    continue;
+                }
                 sb.append(name);
                 sb.append(NAME_VALUE_SEPARATOR);
                 sb.append(value);
diff --git a/common/src/test/java/org/apache/rocketmq/common/message/MessageDecoderTest.java
b/common/src/test/java/org/apache/rocketmq/common/message/MessageDecoderTest.java
index 82ad271..fde523d 100644
--- a/common/src/test/java/org/apache/rocketmq/common/message/MessageDecoderTest.java
+++ b/common/src/test/java/org/apache/rocketmq/common/message/MessageDecoderTest.java
@@ -246,4 +246,23 @@ public class MessageDecoderTest {
 
         assertThat("abc").isEqualTo(decodedMsg.getTopic());
     }
-}
+
+    public void testNullValueProperty() throws Exception {
+        MessageExt msg = new MessageExt();
+        msg.setBody("x".getBytes());
+        msg.setTopic("x");
+        msg.setBornHost(new InetSocketAddress("127.0.0.1", 9000));
+        msg.setStoreHost(new InetSocketAddress("127.0.0.1", 9000));
+        String key = "NullValueKey";
+        msg.putProperty(key, null);
+        try {
+            byte[] encode = MessageDecoder.encode(msg, false);
+            MessageExt decode = MessageDecoder.decode(ByteBuffer.wrap(encode));
+            assertThat(decode.getProperty(key)).isNull();
+        } catch (Exception e) {
+            e.printStackTrace();
+            assertThat(Boolean.FALSE).isTrue();
+        }
+    }
+
+}
\ No newline at end of file


Mime
View raw message