Skip to content

Commit a26b30d

Browse files
author
Martin Traverse
authored
GH-35553: [JAVA] Fix unwrap() in NettyArrowBuf (#35554)
Suggested fix for #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: #35553 Authored-by: Martin Traverse <[email protected]> Signed-off-by: David Li <[email protected]>
1 parent 053b5ee commit a26b30d

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

java/memory/memory-netty/src/main/java/io/netty/buffer/NettyArrowBuf.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,14 @@ public synchronized ByteBuf capacity(int newCapacity) {
110110

111111
@Override
112112
public ByteBuf unwrap() {
113-
throw new UnsupportedOperationException("Unwrap not supported.");
113+
114+
// According to Netty's ByteBuf interface, unwrap() should return null if the buffer cannot be unwrapped
115+
// https://github.com/netty/netty/blob/9fe796e10a433b6cd20ad78b2c39cd56b86ccd2e/buffer/src/main/java/io/netty/buffer/ByteBuf.java#L305
116+
117+
// Throwing here breaks toString() in AbstractByteBuf
118+
// Since toString() is used to build debug / error messages, this can cause strange behavior
119+
120+
return null;
114121
}
115122

116123
@Override

java/memory/memory-netty/src/test/java/io/netty/buffer/TestNettyArrowBuf.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,15 @@ public void testGetCompositeBuffer() {
138138
byteBufs.component(0).release();
139139
}
140140
}
141+
142+
@Test
143+
public void testUnwrapReturnsNull() {
144+
try (BufferAllocator allocator = new RootAllocator(128);
145+
ArrowBuf buf = allocator.buffer(20);
146+
) {
147+
NettyArrowBuf nettyBuf = NettyArrowBuf.unwrapBuffer(buf);
148+
// NettyArrowBuf cannot be unwrapped, so unwrap() should return null per the Netty ByteBuf API
149+
Assert.assertNull(nettyBuf.unwrap());
150+
}
151+
}
141152
}

0 commit comments

Comments
 (0)