Proper ClassLoader with ClassShutter

Tony Zakula tonyzakula at gmail.com
Sun Mar 20 17:15:50 UTC 2016


Hey All,

I am using a ClassShutter to limit the Java classes scripts can use, but I
am wondering how to use the proper ClassLoader in the constructor.  The
following seems to work fine, but is there a better way?  Our
initialization code looks like the following:

        // There is a bug on startup sometimes with persistent code cache
where you get a null pointer
        // https://bugs.openjdk.java.net/browse/JDK-8134304 - We can
swallow it because things run normally
        ScriptEngine engine = null;

        // Custom ClassFilter
        NashornClassFilter nashornClassFilter = new NashornClassFilter();

        try {
            engine = new NashornScriptEngineFactory().getScriptEngine(new
String[]{"-ccs=1000", "-ot=true", "-pcc=true"},
ClassLoader.getSystemClassLoader(), nashornClassFilter);
        }
        catch (Exception e) {}

Thanks,

Tony


More information about the nashorn-dev mailing list