[#5629] Ensure direct ByteBuffer are wrapped in as direct ByteBuf.

Motivation:

We need to check if a ByteBuffer is direct via isDirect() to detect if its direct as hasArray() may also return true for a direct ByteBuffer.

See also:
https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html#allocateDirect-int-

Modifications:

Add isDirect() check.

Result:

Correct wrap a direct ByteBuffer in all cases.
This commit is contained in:
Norman Maurer 2016-08-04 14:23:23 +02:00
parent e5b45f120a
commit 76a3ea699d

View File

@ -183,7 +183,7 @@ public final class Unpooled {
if (!buffer.hasRemaining()) {
return EMPTY_BUFFER;
}
if (buffer.hasArray()) {
if (!buffer.isDirect() && buffer.hasArray()) {
return wrappedBuffer(
buffer.array(),
buffer.arrayOffset() + buffer.position(),