Instantiating sun.misc.Unsafe via bootclasspath
suggest changepackage foo.bar;
import sun.misc.Unsafe;
public class UnsafeLoader {
public static Unsafe loadUnsafe() {
return Unsafe.getUnsafe();
}
}
Unsafe.getUnsafe() throws SecurityException unless the caller’s class loader is the bootstrap class loader. On Java 8, append this class’s jar to the boot classpath instead of replacing rt.jar:
java -Xbootclasspath/a:./UnsafeLoader.jar foo.bar.MyApp
foo.bar.MyApp can then call UnsafeLoader.loadUnsafe(). Java 9 removed rt.jar. The colon in the boot-classpath path is the Unix separator.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents