GeezerVison is showing github.com — Auto-port 5.0: AbstractByteBuf._internalNioBuffer() might throw excep… · netty/netty@5f9f4ae
File tree
Expand file treeCollapse file tree
Open diff view settings
main/java/io/netty/buffer test/java/io/netty/buffer
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: buffer/src/main/java/io/netty/buffer/AbstractByteBuf.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1498,6 +1498,6 @@ long _memoryAddress() { |
1498 | 1498 | } |
1499 | 1499 |
|
1500 | 1500 | ByteBuffer _internalNioBuffer() { |
1501 | | - return internalNioBuffer(0, maxFastWritableBytes()); |
| 1501 | + return internalNioBuffer(0, capacity()); |
1502 | 1502 | } |
1503 | 1503 | } |
Collapse file
Copy file name to clipboardExpand all lines: buffer/src/test/java/io/netty/buffer/AbstractByteBufTest.java +19Lines changed: 19 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
75 | 75 | import static io.netty.buffer.Unpooled.wrappedBuffer; |
76 | 76 | import static io.netty.util.internal.EmptyArrays.EMPTY_BYTES; |
77 | 77 | import static org.assertj.core.api.Assertions.assertThat; |
| 78 | +import static org.assertj.core.api.Assumptions.assumeThat; |
78 | 79 | import static org.junit.jupiter.api.Assertions.assertArrayEquals; |
79 | 80 | import static org.junit.jupiter.api.Assertions.assertEquals; |
80 | 81 | import static org.junit.jupiter.api.Assertions.assertFalse; |
@@ -6474,4 +6475,22 @@ public void testWriteCharSequence() { |
6474 | 6475 | assertNotSame(capacity, buffer.capacity()); |
6475 | 6476 | buffer.release(); |
6476 | 6477 | } |
| 6478 | + |
| 6479 | + @Test |
| 6480 | + public void test_internalNioBuffer() { |
| 6481 | + ByteBuf buf = buffer(8, 16); |
| 6482 | + ByteBuf buffer = buf; |
| 6483 | + if (buf instanceof SimpleLeakAwareByteBuf) { |
| 6484 | + buffer = buf.unwrap(); |
| 6485 | + } |
| 6486 | + assumeThat(buffer).isInstanceOf(AbstractByteBuf.class); |
| 6487 | + try { |
| 6488 | + ByteBuffer nioBuffer = ((AbstractByteBuf) buffer)._internalNioBuffer(); |
| 6489 | + assertEquals(0, nioBuffer.position()); |
| 6490 | + assertThat(nioBuffer.remaining()).isGreaterThanOrEqualTo(8); |
| 6491 | + } finally { |
| 6492 | + buf.release(); |
| 6493 | + } |
| 6494 | + } |
| 6495 | + |
6477 | 6496 | } |