Skip to content
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

Empty NettyByteBuffer.asByteBuffer() returns ByteBuffer with zero capacity [SPR-16068] #20617

spring-issuemaster opened this issue Oct 13, 2017 · 1 comment


None yet
2 participants
Copy link

commented Oct 13, 2017

Oleg Alexeyev opened SPR-16068 and commented

DataBuffer allocated with NettyDataBufferFactor.allocateBuffer(capacity) on asByteBuffer() returns one with zero capacity. It makes it useless for reading data e.g. from ReadableByteChannel.

The reason is that NettyDataBuffer.asByteBuffer() calls ByteBuf.nioBuffer() without parameters, which uses ByteBuf.readableBytes() as length. Perhaps it should call byteBuf.nioBuffer(0, byteBuf.capacity()) instead.


ByteBuf byteBuf = dataBuffer.getNativeBuffer();
ByteBuffer byteBuffer = byteBuf.nioBuffer(0, byteBuf.capacity());
int read =;

Affects: 5.0 GA

Issue Links:

  • #20619,...) may corrupt data when used with NettyDataBuffers

Referenced from: commits c7a1526

1 votes, 3 watchers


This comment has been minimized.

Copy link
Collaborator Author

commented Oct 19, 2017

Arjen Poutsma commented

Fixed in c7a1526 by introducing DataBuffer.asByteBuffer(int, int), and also exposing the DataBuffer's read position, write position and capacity.

The reason for doing it this way, rather than the suggested byteBuf.nioBuffer(0, byteBuf.capacity(), is that we want DataBuffer to follow Netty's ByteBuf contract as closely as possible, and not introduce too much of our own logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.