This is an automated email from the ASF dual-hosted git repository.

rexxiong pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/celeborn.git


The following commit(s) were added to refs/heads/main by this push:
     new 0fc7827ab [CELEBORN-2036] Fix NPE when TransportMessage has null 
payload
0fc7827ab is described below

commit 0fc7827ab86471c8dd30d2f6297c5a446c179b38
Author: Jray <[email protected]>
AuthorDate: Thu Jun 26 10:43:12 2025 +0800

    [CELEBORN-2036] Fix NPE when TransportMessage has null payload
    
    ### What changes were proposed in this pull request?
    As title.
    
    ### Why are the changes needed?
    An NPE will be thrown when the ```TransportMessage``` payload is null, and 
there is no check here.
    
    ### Does this PR introduce _any_ user-facing change?
    No.
    
    ### How was this patch tested?
    Existing ut.
    
    Closes #3330 from Jraaay/main.
    
    Authored-by: Jray <[email protected]>
    Signed-off-by: Shuang <[email protected]>
---
 .../celeborn/common/network/protocol/TransportMessage.java       | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git 
a/common/src/main/java/org/apache/celeborn/common/network/protocol/TransportMessage.java
 
b/common/src/main/java/org/apache/celeborn/common/network/protocol/TransportMessage.java
index 137c2e710..1e729332f 100644
--- 
a/common/src/main/java/org/apache/celeborn/common/network/protocol/TransportMessage.java
+++ 
b/common/src/main/java/org/apache/celeborn/common/network/protocol/TransportMessage.java
@@ -132,11 +132,14 @@ public class TransportMessage implements Serializable {
   }
 
   public ByteBuffer toByteBuffer() {
-    int totalBufferSize = payload.length + 4 + 4;
+    int payloadLength = payload != null ? payload.length : 0;
+    int totalBufferSize = payloadLength + 4 + 4;
     ByteBuffer buffer = ByteBuffer.allocate(totalBufferSize);
     buffer.putInt(messageTypeValue);
-    buffer.putInt(payload.length);
-    buffer.put(payload);
+    buffer.putInt(payloadLength);
+    if (payload != null) {
+      buffer.put(payload);
+    }
     buffer.flip();
     return buffer;
   }

Reply via email to