Skip to content

Commit 9ddc319

Browse files
committed
test: Change test to validate we cannot access DirectBuffer
1 parent bec8737 commit 9ddc319

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

memory/memory-core/src/main/java/org/apache/arrow/memory/util/MemoryUtil.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,14 @@ public Object run() {
8787
try {
8888
addressField.setAccessible(true);
8989
maybeOffset = UNSAFE.objectFieldOffset(addressField);
90-
} catch (InaccessibleObjectException e){
90+
} catch (InaccessibleObjectException e) {
9191
maybeOffset = -1;
92-
logger.debug("Cannot access the address field of java.nio.Buffer. DirectBuffer operations wont be available", e);
92+
logger.debug(
93+
"Cannot access the address field of java.nio.Buffer. DirectBuffer operations wont be available",
94+
e);
9395
}
9496
BYTE_BUFFER_ADDRESS_OFFSET = maybeOffset;
9597

96-
9798
Constructor<?> directBufferConstructor;
9899
long address = -1;
99100
final ByteBuffer direct = ByteBuffer.allocateDirect(1);
@@ -168,7 +169,7 @@ public Object run() {
168169
* @return address of the underlying memory.
169170
*/
170171
public static long getByteBufferAddress(ByteBuffer buf) {
171-
if(BYTE_BUFFER_ADDRESS_OFFSET != -1) {
172+
if (BYTE_BUFFER_ADDRESS_OFFSET != -1) {
172173
return UNSAFE.getLong(buf, BYTE_BUFFER_ADDRESS_OFFSET);
173174
}
174175
throw new UnsupportedOperationException(

memory/memory-core/src/test/java/org/apache/arrow/memory/TestOpens.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static org.junit.jupiter.api.Assertions.assertTrue;
2121
import static org.junit.jupiter.api.condition.JRE.JAVA_16;
2222

23+
import org.apache.arrow.memory.util.MemoryUtil;
2324
import org.junit.jupiter.api.Test;
2425
import org.junit.jupiter.api.condition.EnabledForJreRange;
2526

@@ -34,18 +35,15 @@ public void testMemoryUtilFailsLoudly() {
3435
Throwable e =
3536
assertThrows(
3637
Throwable.class,
37-
() -> {
38-
BufferAllocator allocator = new RootAllocator();
39-
allocator.close();
40-
});
38+
() -> MemoryUtil.directBuffer(0, 10));
4139
boolean found = false;
4240
while (e != null) {
43-
e = e.getCause();
44-
if (e instanceof RuntimeException
45-
&& e.getMessage().contains("Failed to initialize MemoryUtil")) {
41+
if (e instanceof UnsupportedOperationException
42+
&& e.getMessage().contains("java.nio.DirectByteBuffer.<init>(long, int) not available")) {
4643
found = true;
4744
break;
4845
}
46+
e = e.getCause();
4947
}
5048
assertTrue(found, "Expected exception was not thrown");
5149
}

0 commit comments

Comments
 (0)