File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed
memory/memory-core/src/main/java/org/apache/arrow/memory/util Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -82,9 +82,17 @@ public Object run() {
8282 BYTE_ARRAY_BASE_OFFSET = UNSAFE .arrayBaseOffset (byte [].class );
8383
8484 // get the offset of the address field in a java.nio.Buffer object
85+ long maybeOffset ;
8586 Field addressField = java .nio .Buffer .class .getDeclaredField ("address" );
86- addressField .setAccessible (true );
87- BYTE_BUFFER_ADDRESS_OFFSET = UNSAFE .objectFieldOffset (addressField );
87+ try {
88+ addressField .setAccessible (true );
89+ maybeOffset = UNSAFE .objectFieldOffset (addressField );
90+ } catch (InaccessibleObjectException e ){
91+ maybeOffset = -1 ;
92+ logger .debug ("Cannot access the address field of java.nio.Buffer. DirectBuffer operations wont be available" , e );
93+ }
94+ BYTE_BUFFER_ADDRESS_OFFSET = maybeOffset ;
95+
8896
8997 Constructor <?> directBufferConstructor ;
9098 long address = -1 ;
@@ -160,7 +168,11 @@ public Object run() {
160168 * @return address of the underlying memory.
161169 */
162170 public static long getByteBufferAddress (ByteBuffer buf ) {
163- return UNSAFE .getLong (buf , BYTE_BUFFER_ADDRESS_OFFSET );
171+ if (BYTE_BUFFER_ADDRESS_OFFSET != -1 ) {
172+ return UNSAFE .getLong (buf , BYTE_BUFFER_ADDRESS_OFFSET );
173+ }
174+ throw new UnsupportedOperationException (
175+ "Byte buffer address cannot be obtained because sun.misc.Unsafe or java.nio.DirectByteBuffer.<init>(long, int) is not available" );
164176 }
165177
166178 private MemoryUtil () {}
You can’t perform that action at this time.
0 commit comments