GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Throw UnsupportedOperationException from AdaptiveByteBuf.memoryAddres… · netty/netty@60d9baf

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • buffer/src
    • main/java/io/netty/buffer
      • AdaptivePoolingAllocator.java
    • test/java/io/netty/buffer
      • AbstractByteBufTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java‎

Copy file name to clipboardExpand all lines: buffer/src/main/java/io/netty/buffer/AdaptivePoolingAllocator.java
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2279,13 +2279,16 @@ public boolean hasMemoryAddress() {
22792279
@Override
22802280
public long memoryAddress() {
22812281
ensureAccessible();
2282+
if (!hasMemoryAddress) {
2283+
throw new UnsupportedOperationException();
2284+
}
22822285
return _memoryAddress();
22832286
}
22842287

22852288
@Override
22862289
long _memoryAddress() {
22872290
AbstractByteBuf root = rootParent;
2288-
return root != null ? root._memoryAddress() + startIndex : 0L;
2291+
return root != null && hasMemoryAddress ? root._memoryAddress() + startIndex : 0L;
22892292
}
22902293

22912294
@Override
Collapse file

‎buffer/src/test/java/io/netty/buffer/AbstractByteBufTest.java‎

Copy file name to clipboardExpand all lines: buffer/src/test/java/io/netty/buffer/AbstractByteBufTest.java
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
8080
import static org.junit.jupiter.api.Assertions.assertEquals;
8181
import static org.junit.jupiter.api.Assertions.assertFalse;
82+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
8283
import static org.junit.jupiter.api.Assertions.assertNotSame;
8384
import static org.junit.jupiter.api.Assertions.assertSame;
8485
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -4561,6 +4562,21 @@ public void testMemoryAddressAfterRelease() {
45614562
}
45624563
}
45634564

4565+
@Test
4566+
public void testMemoryAddressUnsupportedWhenNoMemoryAddress() {
4567+
ByteBuf buf = newBuffer(16);
4568+
try {
4569+
if (buf.hasMemoryAddress()) {
4570+
// Must not throw, and must not be the "no address" marker.
4571+
assertNotEquals(0L, buf.memoryAddress());
4572+
} else {
4573+
assertThrows(UnsupportedOperationException.class, () -> buf.memoryAddress());
4574+
}
4575+
} finally {
4576+
buf.release();
4577+
}
4578+
}
4579+
45644580
@Test
45654581
public void testSliceAfterRelease() {
45664582
assertThrows(IllegalReferenceCountException.class, new Executable() {

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.