[util] get rid of explicit reference to internal Unsafe class in ByteBufferUtil
authorNikolay Chashnikov <Nikolay.Chashnikov@jetbrains.com>
Wed, 12 Aug 2020 17:41:26 +0000 (20:41 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Wed, 12 Aug 2020 18:36:02 +0000 (18:36 +0000)
This is needed to be able to compile intellij.platform.util module using JDK 11 (IDEA-248086).

GitOrigin-RevId: a21f7118b30006cb935ef9cb27a34e093bff3987

platform/util/src/com/intellij/util/io/ByteBufferUtil.java

index 7a91440fe45ce2ab16fe42cfd1bb00547bea6069..dc9a7da78ef84a4597b90ea552af766453c00fcf 100644 (file)
@@ -6,7 +6,6 @@ import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.util.SystemInfoRt;
 import com.intellij.util.concurrency.AtomicFieldUpdater;
 import org.jetbrains.annotations.NotNull;
-import sun.misc.Unsafe;
 
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
@@ -23,11 +22,11 @@ public final class ByteBufferUtil {
 
     if (SystemInfoRt.IS_AT_LEAST_JAVA9) {
       // in Java 9+, the "official" dispose method is sun.misc.Unsafe#invokeCleaner
-      Unsafe unsafe = AtomicFieldUpdater.getUnsafe();
+      Object unsafe = AtomicFieldUpdater.getUnsafe();
       try {
         MethodType type = MethodType.methodType(void.class, ByteBuffer.class);
-        @SuppressWarnings("JavaLangInvokeHandleSignature") MethodHandle handle = MethodHandles.lookup().findVirtual(Unsafe.class, "invokeCleaner", type);
-        handle.invokeExact(unsafe, buffer);
+        @SuppressWarnings("JavaLangInvokeHandleSignature") MethodHandle handle = MethodHandles.lookup().findVirtual(unsafe.getClass(), "invokeCleaner", type);
+        handle.invoke(unsafe, buffer);
         return true;
       }
       catch (Throwable t) {