diff --git a/buffer/src/main/java/io/netty/buffer/AbstractByteBufAllocator.java b/buffer/src/main/java/io/netty/buffer/AbstractByteBufAllocator.java index 920b3fb46d..9e15822b4c 100644 --- a/buffer/src/main/java/io/netty/buffer/AbstractByteBufAllocator.java +++ b/buffer/src/main/java/io/netty/buffer/AbstractByteBufAllocator.java @@ -127,7 +127,7 @@ public abstract class AbstractByteBufAllocator implements ByteBufAllocator { @Override public ByteBuf ioBuffer() { - if (PlatformDependent.hasUnsafe()) { + if (PlatformDependent.hasUnsafe() || isDirectBufferPooled()) { return directBuffer(DEFAULT_INITIAL_CAPACITY); } return heapBuffer(DEFAULT_INITIAL_CAPACITY); @@ -135,7 +135,7 @@ public abstract class AbstractByteBufAllocator implements ByteBufAllocator { @Override public ByteBuf ioBuffer(int initialCapacity) { - if (PlatformDependent.hasUnsafe()) { + if (PlatformDependent.hasUnsafe() || isDirectBufferPooled()) { return directBuffer(initialCapacity); } return heapBuffer(initialCapacity); @@ -143,7 +143,7 @@ public abstract class AbstractByteBufAllocator implements ByteBufAllocator { @Override public ByteBuf ioBuffer(int initialCapacity, int maxCapacity) { - if (PlatformDependent.hasUnsafe()) { + if (PlatformDependent.hasUnsafe() || isDirectBufferPooled()) { return directBuffer(initialCapacity, maxCapacity); } return heapBuffer(initialCapacity, maxCapacity); diff --git a/buffer/src/test/java/io/netty/buffer/PooledByteBufAllocatorTest.java b/buffer/src/test/java/io/netty/buffer/PooledByteBufAllocatorTest.java index b1396373bc..4f9ce334a6 100644 --- a/buffer/src/test/java/io/netty/buffer/PooledByteBufAllocatorTest.java +++ b/buffer/src/test/java/io/netty/buffer/PooledByteBufAllocatorTest.java @@ -92,6 +92,25 @@ public class PooledByteBufAllocatorTest extends AbstractByteBufAllocatorTest