This is an automated email from the ASF dual-hosted git repository.
RongtongJin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git
The following commit(s) were added to refs/heads/master by this push:
new c46bc3fa [C#] Fix SetBody validation logic to correctly reject null
and empty body (#1268)
c46bc3fa is described below
commit c46bc3faa381a796b526205fbda0cb79130893f0
Author: guyinyou <[email protected]>
AuthorDate: Thu Jun 11 15:40:47 2026 +0800
[C#] Fix SetBody validation logic to correctly reject null and empty body
(#1268)
The original condition `null != body || body.Length == 0` had two bugs:
- When body is null, it short-circuits to evaluating `body.Length`, causing
NullReferenceException instead of a proper ArgumentException.
- When body is a non-null empty array (byte[0]), `null != body` is true,
so the empty body passes validation silently.
Fix to `null != body && body.Length > 0`, consistent with the Java
implementation which uses `ArrayUtils.isNotEmpty(body)`.
Co-authored-by: guyinyou <[email protected]>
---
csharp/rocketmq-client-csharp/Message.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/csharp/rocketmq-client-csharp/Message.cs
b/csharp/rocketmq-client-csharp/Message.cs
index 85b129e6..38f0bcc4 100644
--- a/csharp/rocketmq-client-csharp/Message.cs
+++ b/csharp/rocketmq-client-csharp/Message.cs
@@ -112,7 +112,7 @@ namespace Org.Apache.Rocketmq
public Builder SetBody(byte[] body)
{
- Preconditions.CheckArgument(null != body || body.Length == 0,
"body should not be empty");
+ Preconditions.CheckArgument(null != body && body.Length > 0,
"body should not be empty");
_body = body;
return this;
}