de.thksystems.util.reflection.UnsafeUtils Maven / Gradle / Ivy
package de.thksystems.util.reflection;
import java.lang.reflect.Field;
import sun.misc.Unsafe;
/**
* Access to the internal Unsafe class.
*
* Use it only, if you really, really, really, really, really know, what you are doing.
*
* It may not work with all java implementations.
*/
@SuppressWarnings("restriction")
public final class UnsafeUtils {
private UnsafeUtils() {
}
/**
* Gets the internal Unsafe class.
*/
public static Unsafe getUnsafe() {
try {
Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe");
unsafeField.setAccessible(true);
return (Unsafe) unsafeField.get(null);
} catch (IllegalAccessException | NoSuchFieldException | SecurityException e) {
return null;
}
}
}