1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-23 00:08:51 -05:00

Make sure not to expose public locks

This commit is contained in:
Reinhard Pointner 2019-02-11 14:34:02 +07:00
parent f0e3b5fa46
commit 580f2bd8f4

View File

@ -224,10 +224,7 @@ public class ExpressionFormat extends Format {
return compilation;
}
private static ScriptEngine engine;
private static Map<String, CompiledScript> scriptletCache = new HashMap<String, CompiledScript>();
protected static ScriptEngine createScriptEngine() {
protected static Compilable createScriptEngine() {
CompilerConfiguration config = new CompilerConfiguration();
// include default functions
@ -239,27 +236,30 @@ public class ExpressionFormat extends Format {
return new GroovyScriptEngineImpl(classLoader);
}
protected static synchronized ScriptEngine getGroovyScriptEngine() throws ScriptException {
if (engine == null) {
engine = createScriptEngine();
}
return engine;
}
private static Compilable engine;
private static Map<String, CompiledScript> scriptletCache = new HashMap<String, CompiledScript>();
protected static synchronized CompiledScript compileScriptlet(String expression) throws ScriptException {
protected static CompiledScript compileScriptlet(String expression) throws ScriptException {
// simple expressions like {n} don't need to be interpreted by the script engine
if (SourceVersion.isIdentifier(expression) && !SourceVersion.isKeyword(expression)) {
return new Variable(expression);
}
synchronized (scriptletCache) {
CompiledScript scriptlet = scriptletCache.get(expression);
if (scriptlet == null) {
Compilable engine = (Compilable) getGroovyScriptEngine();
// lazy initialize script engine
if (engine == null) {
engine = createScriptEngine();
}
// compile and cache script
scriptlet = engine.compile(expression);
scriptletCache.put(expression, scriptlet);
}
return scriptlet;
}
}
private static class Variable extends CompiledScript {