How do I get the instance of the unsafe class?
I always get the security exception. I listed the code of the OpenJDK 6 implementation. I would like to mess around with
If you use Spring, you can use its class called UnsafeUtils
at org.springframework.objenesis.instantiator.util.UnsafeUtils
public final class UnsafeUtils {
private static final Unsafe unsafe;
private UnsafeUtils() {
}
public static Unsafe getUnsafe() {
return unsafe;
}
static {
Field f;
try {
f = Unsafe.class.getDeclaredField("theUnsafe");
} catch (NoSuchFieldException var3) {
throw new ObjenesisException(var3);
}
f.setAccessible(true);
try {
unsafe = (Unsafe)f.get((Object)null);
} catch (IllegalAccessException var2) {
throw new ObjenesisException(var2);
}
}
}