ThreadLocalByteBufferPool implements ByteBufferPool { @Override public void release(ByteBuffer buffer) { Objects.requireNonNull(buffer); boolean directBuffer = buffer.isDirect(); if (directBuffer == direct && !buffer.isReadOnly()) { final ByteBuffer byteBuffer = bytesPool.get(); if (byteBuffer != buffer) { if (byteBuffer == null || buffer.capacity() > byteBuffer.capacity()) { if (byteBuffer != null) { if (directBuffer) { PlatformDependent.freeDirectBuffer(byteBuffer); } } bytesPool.set(buffer); } else { if (directBuffer) { PlatformDependent.freeDirectBuffer(buffer); } } } } } ThreadLocalByteBufferPool(boolean direct); @Override ByteBuffer borrow(final int size, boolean zeroed); @Override void release(ByteBuffer buffer);  }
@Test(expected = NullPointerException.class) public void shouldFailPoolingNullBuffer() { pool.release(null); }