Instantiating sun.misc.Unsafe via bootclasspath

suggest change
package 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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents