Skip to content

Commit

Permalink
apacheGH-35553: [JAVA] Fix unwrap() in NettyArrowBuf (apache#35554)
Browse files Browse the repository at this point in the history
Suggested fix for apache#35553

No API changes, this just brings the implementation in line with the API as specified by Netty.

CI for Java run successfully here (not sure if this is publically visible):

https://github.com/martin-traverse/arrow/actions/runs/4949700024

* Closes: apache#35553

Authored-by: Martin Traverse <martin.traverse@accenture.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
  • Loading branch information
martin-traverse authored and ArgusLi committed May 15, 2023
1 parent 71306b7 commit a92408e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,14 @@ public synchronized ByteBuf capacity(int newCapacity) {

@Override
public ByteBuf unwrap() {
throw new UnsupportedOperationException("Unwrap not supported.");

// According to Netty's ByteBuf interface, unwrap() should return null if the buffer cannot be unwrapped
// https://github.com/netty/netty/blob/9fe796e10a433b6cd20ad78b2c39cd56b86ccd2e/buffer/src/main/java/io/netty/buffer/ByteBuf.java#L305

// Throwing here breaks toString() in AbstractByteBuf
// Since toString() is used to build debug / error messages, this can cause strange behavior

return null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,15 @@ public void testGetCompositeBuffer() {
byteBufs.component(0).release();
}
}

@Test
public void testUnwrapReturnsNull() {
try (BufferAllocator allocator = new RootAllocator(128);
ArrowBuf buf = allocator.buffer(20);
) {
NettyArrowBuf nettyBuf = NettyArrowBuf.unwrapBuffer(buf);
// NettyArrowBuf cannot be unwrapped, so unwrap() should return null per the Netty ByteBuf API
Assert.assertNull(nettyBuf.unwrap());
}
}
}

0 comments on commit a92408e

Please sign in to comment.