[FIX] CommonHelper.newScriptEngine

This commit is contained in:
Gravita 2021-03-20 19:17:03 +07:00
parent cd5c78c413
commit 6127e92ce5

View file

@ -13,9 +13,16 @@
public final class CommonHelper { public final class CommonHelper {
public static final ScriptEngineManager scriptManager = new ScriptEngineManager(); private static ScriptEngineFactory nashornFactory;
public static final ScriptEngineFactory nashornFactory = getEngineFactories(scriptManager); static {
try {
ScriptEngineManager scriptManager = new ScriptEngineManager();
nashornFactory = getEngineFactories(scriptManager);
} catch (Throwable e) {
nashornFactory = null;
}
}
private CommonHelper() { private CommonHelper() {
} }
@ -48,7 +55,10 @@ public static String multiReplace(Pattern[] pattern, String from, String replace
} }
public static ScriptEngine newScriptEngine() { public static ScriptEngine newScriptEngine() {
return Objects.requireNonNull(nashornFactory).getScriptEngine(); if(nashornFactory == null) {
throw new UnsupportedOperationException("ScriptEngine not supported");
}
return nashornFactory.getScriptEngine();
} }
public static Thread newThread(String name, boolean daemon, Runnable runnable) { public static Thread newThread(String name, boolean daemon, Runnable runnable) {