-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Fix DefaultDataBuffer#getNativeBuffer()
to set correct limit
#32009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix DefaultDataBuffer#getNativeBuffer()
to set correct limit
#32009
Conversation
* @return the wrapped byte buffer | ||
*/ | ||
public ByteBuffer getNativeBuffer() { | ||
this.byteBuffer.position(this.readPosition); | ||
this.byteBuffer.limit(readableByteCount()); | ||
this.byteBuffer.limit(this.writePosition); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0 1 2 3 4 5 6 7 8 9
^ ^
read write
When readPosition: 7
and writePosition: 10
,
Current getNativebuffer
return bytebuffer with limit: 3
(readableByteCount(), writePos - readPos)
But I think we should set limit: 10
(writePos) correctly.
Like this commit, maybe we set redableByteCount() as length
on bytebuffer's limit by mistake 😅
177104b
to
cd85736
Compare
cd85736
to
d357085
Compare
@Test // gh-30967 | ||
void getNativeBuffer() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…iveBuffer * gh-32009: Polishing external contribution Set correct limit in DefaultDataBuffer::getNativeBuffer
Thanks for supplying a PR. I decided to change the fix by returning a duplicate with independent position and limit, instead changing these on the buffer itself. This is arguably the way it should have been since 5fc1806. |
Oh thank you for your additional polishing :) I'm so happy that this is my first contribution(969d0bd) on spring-framework! |
Closes gh-30967
Motivation
DefaultDataBuffer#getNativeBuffer
setbyteBuffer#limit
asreadableByteCount()
incorrectly so fix towritePosition
Modification
DefaultDataBuffer#getNativeBuffer()
to set correct limit aswritePosition
instead ofreadableByteCount()
Result
DefaultDataBuffer#getNativeBuffer()
return native bytebuffer with correct limit