[Bug] RpcClientUtils.encodeBody overwrites the caller's ByteBuffer mark
Description
RpcClientUtils.encodeBody in the remoting module mutates buffer state it does not own:
} else if (body instanceof ByteBuffer) {
ByteBuffer buffer = (ByteBuffer)body;
buffer.mark();
byte[] data = new byte[buffer.remaining()];
buffer.get(data);
buffer.reset();
return data;
}The method restores the buffer's position (via mark/reset) but overwrites whatever mark the caller had previously set. A caller that did buffer.mark() at position 1, advanced to position 3, then passed the buffer through encodeBody gets back a buffer whose mark is now 3; a later buffer.reset() jumps to 3 instead of 1. Encoding a body therefore has an observable side effect on the caller's buffer beyond reading it.
Additionally, when the caller's position/mark/limit are what they are, the encode itself must only read the remaining bytes — which duplicate() achieves without touching the original buffer's position, limit or mark at all.
Expected behavior
encodeBody should be side-effect free on the passed-in ByteBuffer: read the remaining bytes from buffer.duplicate() and leave the original buffer's position, limit and mark untouched.
Source: apache/rocketmq