From 0fc7827ab86471c8dd30d2f6297c5a446c179b38 Mon Sep 17 00:00:00 2001 From: Jray <1075860716@qq.com> Date: Thu, 26 Jun 2025 10:43:12 +0800 Subject: [PATCH] [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 <1075860716@qq.com> Signed-off-by: Shuang --- .../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; }