--- 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 @@ *