de.thksystems.util.reflection.UnsafeUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cumin Show documentation
Show all versions of cumin Show documentation
Commons for lang, crypto, xml, dom, text, csv, reflection, annotations, parsing, ...
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;
}
}
}