diff --git a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationService.java b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationService.java index 6958da4ed6d..798bcb33251 100644 --- a/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationService.java +++ b/bundles/org.openhab.core.automation.module.script/src/main/java/org/openhab/core/automation/module/script/ScriptTransformationService.java @@ -38,9 +38,9 @@ import org.openhab.core.automation.module.script.profile.ScriptProfile; import org.openhab.core.common.ThreadPoolManager; import org.openhab.core.common.registry.RegistryChangeListener; -import org.openhab.core.transform.Transformation; import org.openhab.core.config.core.ConfigOptionProvider; import org.openhab.core.config.core.ParameterOption; +import org.openhab.core.transform.Transformation; import org.openhab.core.transform.TransformationException; import org.openhab.core.transform.TransformationRegistry; import org.openhab.core.transform.TransformationService; @@ -148,10 +148,10 @@ public void deactivate() { try { CompiledScript compiledScript = scriptRecord.compiledScript; - if (compiledScript == null && scriptEngineContainer.getScriptEngine() instanceof Compilable) { + if (compiledScript == null + && scriptEngineContainer.getScriptEngine()instanceof Compilable scriptCompiler) { // no compiled script available but compiling is supported - compiledScript = ((Compilable) scriptEngineContainer.getScriptEngine()) - .compile(scriptRecord.script); + compiledScript = scriptCompiler.compile(scriptRecord.script); scriptRecord.compiledScript = compiledScript; } @@ -218,14 +218,13 @@ private void disposeScriptRecord(ScriptRecord scriptRecord) { } private void disposeScriptEngine(ScriptEngine scriptEngine) { - if (scriptEngine instanceof AutoCloseable) { + if (scriptEngine instanceof AutoCloseable closableScriptEngine) { // we cannot not use ScheduledExecutorService.execute here as it might execute the task in the calling // thread (calling ScriptEngine.close in the same thread may result in a deadlock if the ScriptEngine // tries to Thread.join) scheduler.schedule(() -> { - AutoCloseable closeable = (AutoCloseable) scriptEngine; try { - closeable.close(); + closableScriptEngine.close(); } catch (Exception e) { logger.error("Error while closing script engine", e); } @@ -274,5 +273,4 @@ private static class ScriptRecord { public final Lock lock = new ReentrantLock(); } - }