From 6127e92ce52a85ea56ee298e46f2195c96956eaa Mon Sep 17 00:00:00 2001 From: Gravita Date: Sat, 20 Mar 2021 19:17:03 +0700 Subject: [PATCH] [FIX] CommonHelper.newScriptEngine --- .../pro/gravit/utils/helper/CommonHelper.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/CommonHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/CommonHelper.java index 9e598b09..47ceeb24 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/CommonHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/CommonHelper.java @@ -13,9 +13,16 @@ 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() { } @@ -48,7 +55,10 @@ public static String multiReplace(Pattern[] pattern, String from, String replace } 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) {