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 54d5e6b60f37cf683bc613176ae62edf0402e9c9..d048dde2b92d3b60035f5764dfd27191417c0ef6 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 82ad2714dd2c255eae0067a587aa3467554b0b7f..fde523dba95344b177cb5426ec852e326bec84e4 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