From 76a3ea699ddc50f7aa9348a71b36578cda85a65c Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Thu, 4 Aug 2016 14:23:23 +0200 Subject: [PATCH] [#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. --- buffer/src/main/java/io/netty/buffer/Unpooled.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buffer/src/main/java/io/netty/buffer/Unpooled.java b/buffer/src/main/java/io/netty/buffer/Unpooled.java index faaaabc2cd..420b7fe625 100644 --- a/buffer/src/main/java/io/netty/buffer/Unpooled.java +++ b/buffer/src/main/java/io/netty/buffer/Unpooled.java @@ -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(),