--- old/src/jdk.unsupported/share/classes/sun/misc/Unsafe.java 2020-03-26 16:01:15.000000000 -0700 +++ new/src/jdk.unsupported/share/classes/sun/misc/Unsafe.java 2020-03-26 16:01:15.000000000 -0700 @@ -30,6 +30,7 @@ import jdk.internal.reflect.CallerSensitive; import jdk.internal.reflect.Reflection; +import java.lang.invoke.MethodHandles; import java.lang.reflect.Field; import java.util.Set; @@ -636,6 +637,12 @@ */ @ForceInline public long objectFieldOffset(Field f) { + if (f == null) { + throw new NullPointerException(); + } + if (f.getDeclaringClass().isHiddenClass()) { + throw new UnsupportedOperationException("can't get field offset on a hidden class: " + f); + } return theInternalUnsafe.objectFieldOffset(f); } @@ -658,6 +665,12 @@ */ @ForceInline public long staticFieldOffset(Field f) { + if (f == null) { + throw new NullPointerException(); + } + if (f.getDeclaringClass().isHiddenClass()) { + throw new UnsupportedOperationException("can't get field offset on a hidden class: " + f); + } return theInternalUnsafe.staticFieldOffset(f); } @@ -673,6 +686,12 @@ */ @ForceInline public Object staticFieldBase(Field f) { + if (f == null) { + throw new NullPointerException(); + } + if (f.getDeclaringClass().isHiddenClass()) { + throw new UnsupportedOperationException("can't get base address on a hidden class: " + f); + } return theInternalUnsafe.staticFieldBase(f); } @@ -820,11 +839,16 @@ *
  • String: any object (not just a java.lang.String) *
  • InterfaceMethodRef: (NYI) a method handle to invoke on that call site's arguments * + * + * @deprecated Use the {@link java.lang.invoke.MethodHandles.Lookup#defineHiddenClass(byte[], boolean, MethodHandles.Lookup.ClassOption...)} + * method. + * * @param hostClass context for linkage, access control, protection domain, and class loader * @param data bytes of a class file * @param cpPatches where non-null entries exist, they replace corresponding CP entries in data */ @ForceInline + @Deprecated(since = "15", forRemoval = false) public Class defineAnonymousClass(Class hostClass, byte[] data, Object[] cpPatches) { return theInternalUnsafe.defineAnonymousClass(hostClass, data, cpPatches); }