[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 <lvshuang.xjs@alibaba-inc.com>
This commit is contained in:
parent
3ee3a26220
commit
0fc7827ab8
@ -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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user