From: Florian Hotze Date: Tue, 9 Jul 2024 18:08:30 +0000 (+0200) Subject: [jsscripting] Implement `javax.script.Compilable` (#16970) X-Git-Url: https://git.basschouten.com/?a=commitdiff_plain;h=405f4023ee575844f27227184d350392c8ae87ce;p=openhab-addons.git [jsscripting] Implement `javax.script.Compilable` (#16970) * [jsscripting] Restructure & Comment POM * [jsscripting] Use OPENHAB_TRANSFORMATION_SCRIPT constant from core Signed-off-by: Florian Hotze --- diff --git a/bundles/org.openhab.automation.jsscripting/pom.xml b/bundles/org.openhab.automation.jsscripting/pom.xml index 824527ded0..9041a6a8c5 100644 --- a/bundles/org.openhab.automation.jsscripting/pom.xml +++ b/bundles/org.openhab.automation.jsscripting/pom.xml @@ -29,6 +29,7 @@ + org.apache.maven.plugins maven-dependency-plugin @@ -44,6 +45,7 @@ + com.github.eirslett frontend-maven-plugin @@ -114,6 +116,7 @@ + org.openhab.tools.sat sat-plugin @@ -125,32 +128,33 @@ + + org.graalvm.sdk + graal-sdk + ${graal.version} + org.graalvm.truffle truffle-api ${graal.version} + org.graalvm.js js-scriptengine ${graal.version} - - org.graalvm.sdk - graal-sdk - ${graal.version} - + org.graalvm.regex regex ${graal.version} - + + org.graalvm.js js ${graal.version} - diff --git a/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/DebuggingGraalScriptEngine.java b/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/DebuggingGraalScriptEngine.java index 508e9cf26a..76f1afb2dd 100644 --- a/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/DebuggingGraalScriptEngine.java +++ b/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/DebuggingGraalScriptEngine.java @@ -12,16 +12,19 @@ */ package org.openhab.automation.jsscripting.internal; +import static org.openhab.core.automation.module.script.ScriptTransformationService.OPENHAB_TRANSFORMATION_SCRIPT; + import java.util.Arrays; import java.util.stream.Collectors; +import javax.script.Compilable; import javax.script.Invocable; import javax.script.ScriptContext; import javax.script.ScriptEngine; import org.eclipse.jdt.annotation.Nullable; import org.graalvm.polyglot.PolyglotException; -import org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable; +import org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocableAndCompilableAndAutoCloseable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -31,10 +34,9 @@ import org.slf4j.LoggerFactory; * @author Jonathan Gilbert - Initial contribution * @author Florian Hotze - Improve logger name, Fix memory leak caused by exception logging */ -class DebuggingGraalScriptEngine - extends InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable { +class DebuggingGraalScriptEngine + extends InvocationInterceptingScriptEngineWithInvocableAndCompilableAndAutoCloseable { - private static final String SCRIPT_TRANSFORMATION_ENGINE_IDENTIFIER = "openhab-transformation-script-"; private static final int STACK_TRACE_LENGTH = 5; private @Nullable Logger logger; @@ -91,9 +93,8 @@ class DebuggingGraalScriptEngine { + extends InvocationInterceptingScriptEngineWithInvocableAndCompilableAndAutoCloseable { private static final Logger LOGGER = LoggerFactory.getLogger(OpenhabGraalJSScriptEngine.class); private static final Source GLOBAL_SOURCE; diff --git a/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/scriptengine/DelegatingScriptEngineWithInvocableAndAutocloseable.java b/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/scriptengine/DelegatingScriptEngineWithInvocableAndAutocloseable.java deleted file mode 100644 index 7e00c6af11..0000000000 --- a/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/scriptengine/DelegatingScriptEngineWithInvocableAndAutocloseable.java +++ /dev/null @@ -1,135 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.automation.jsscripting.internal.scriptengine; - -import java.io.Reader; - -import javax.script.Bindings; -import javax.script.Invocable; -import javax.script.ScriptContext; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineFactory; -import javax.script.ScriptException; - -import org.eclipse.jdt.annotation.NonNull; - -/** - * {@link ScriptEngine} implementation that delegates to a supplied ScriptEngine instance. Allows overriding specific - * methods. - * - * @author Jonathan Gilbert - Initial contribution - */ -public abstract class DelegatingScriptEngineWithInvocableAndAutocloseable - implements ScriptEngine, Invocable, AutoCloseable { - protected @NonNull T delegate; - - public DelegatingScriptEngineWithInvocableAndAutocloseable(@NonNull T delegate) { - this.delegate = delegate; - } - - @Override - public Object eval(String s, ScriptContext scriptContext) throws ScriptException { - return delegate.eval(s, scriptContext); - } - - @Override - public Object eval(Reader reader, ScriptContext scriptContext) throws ScriptException { - return delegate.eval(reader, scriptContext); - } - - @Override - public Object eval(String s) throws ScriptException { - return delegate.eval(s); - } - - @Override - public Object eval(Reader reader) throws ScriptException { - return delegate.eval(reader); - } - - @Override - public Object eval(String s, Bindings bindings) throws ScriptException { - return delegate.eval(s, bindings); - } - - @Override - public Object eval(Reader reader, Bindings bindings) throws ScriptException { - return delegate.eval(reader, bindings); - } - - @Override - public void put(String s, Object o) { - delegate.put(s, o); - } - - @Override - public Object get(String s) { - return delegate.get(s); - } - - @Override - public Bindings getBindings(int i) { - return delegate.getBindings(i); - } - - @Override - public void setBindings(Bindings bindings, int i) { - delegate.setBindings(bindings, i); - } - - @Override - public Bindings createBindings() { - return delegate.createBindings(); - } - - @Override - public ScriptContext getContext() { - return delegate.getContext(); - } - - @Override - public void setContext(ScriptContext scriptContext) { - delegate.setContext(scriptContext); - } - - @Override - public ScriptEngineFactory getFactory() { - return delegate.getFactory(); - } - - @Override - public Object invokeMethod(Object o, String s, Object... objects) - throws ScriptException, NoSuchMethodException, IllegalArgumentException { - return delegate.invokeMethod(o, s, objects); - } - - @Override - public Object invokeFunction(String s, Object... objects) throws ScriptException, NoSuchMethodException { - return delegate.invokeFunction(s, objects); - } - - @Override - public T getInterface(Class aClass) { - return delegate.getInterface(aClass); - } - - @Override - public T getInterface(Object o, Class aClass) { - return delegate.getInterface(o, aClass); - } - - @Override - public void close() throws Exception { - delegate.close(); - } -} diff --git a/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/scriptengine/DelegatingScriptEngineWithInvocableAndCompilableAndAutocloseable.java b/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/scriptengine/DelegatingScriptEngineWithInvocableAndCompilableAndAutocloseable.java new file mode 100644 index 0000000000..79a93b9288 --- /dev/null +++ b/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/scriptengine/DelegatingScriptEngineWithInvocableAndCompilableAndAutocloseable.java @@ -0,0 +1,147 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.automation.jsscripting.internal.scriptengine; + +import java.io.Reader; + +import javax.script.Bindings; +import javax.script.Compilable; +import javax.script.CompiledScript; +import javax.script.Invocable; +import javax.script.ScriptContext; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineFactory; +import javax.script.ScriptException; + +import org.eclipse.jdt.annotation.NonNull; + +/** + * {@link ScriptEngine} implementation that delegates to a supplied ScriptEngine instance. Allows overriding specific + * methods. + * + * @author Jonathan Gilbert - Initial contribution + */ +public abstract class DelegatingScriptEngineWithInvocableAndCompilableAndAutocloseable + implements ScriptEngine, Invocable, Compilable, AutoCloseable { + protected @NonNull T delegate; + + public DelegatingScriptEngineWithInvocableAndCompilableAndAutocloseable(@NonNull T delegate) { + this.delegate = delegate; + } + + @Override + public Object eval(String s, ScriptContext scriptContext) throws ScriptException { + return delegate.eval(s, scriptContext); + } + + @Override + public Object eval(Reader reader, ScriptContext scriptContext) throws ScriptException { + return delegate.eval(reader, scriptContext); + } + + @Override + public Object eval(String s) throws ScriptException { + return delegate.eval(s); + } + + @Override + public Object eval(Reader reader) throws ScriptException { + return delegate.eval(reader); + } + + @Override + public Object eval(String s, Bindings bindings) throws ScriptException { + return delegate.eval(s, bindings); + } + + @Override + public Object eval(Reader reader, Bindings bindings) throws ScriptException { + return delegate.eval(reader, bindings); + } + + @Override + public void put(String s, Object o) { + delegate.put(s, o); + } + + @Override + public Object get(String s) { + return delegate.get(s); + } + + @Override + public Bindings getBindings(int i) { + return delegate.getBindings(i); + } + + @Override + public void setBindings(Bindings bindings, int i) { + delegate.setBindings(bindings, i); + } + + @Override + public Bindings createBindings() { + return delegate.createBindings(); + } + + @Override + public ScriptContext getContext() { + return delegate.getContext(); + } + + @Override + public void setContext(ScriptContext scriptContext) { + delegate.setContext(scriptContext); + } + + @Override + public ScriptEngineFactory getFactory() { + return delegate.getFactory(); + } + + @Override + public Object invokeMethod(Object o, String s, Object... objects) + throws ScriptException, NoSuchMethodException, IllegalArgumentException { + return delegate.invokeMethod(o, s, objects); + } + + @Override + public Object invokeFunction(String s, Object... objects) throws ScriptException, NoSuchMethodException { + return delegate.invokeFunction(s, objects); + } + + @Override + public T getInterface(Class aClass) { + return delegate.getInterface(aClass); + } + + @Override + public T getInterface(Object o, Class aClass) { + return delegate.getInterface(o, aClass); + } + + @Override + public CompiledScript compile(String s) throws ScriptException { + return delegate.compile(s); + } + + @Override + public CompiledScript compile(Reader reader) throws ScriptException { + return delegate.compile(reader); + } + + @Override + public void close() throws Exception { + delegate.close(); + } +} diff --git a/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/scriptengine/InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.java b/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/scriptengine/InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.java deleted file mode 100644 index 71501f3973..0000000000 --- a/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/scriptengine/InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable.java +++ /dev/null @@ -1,158 +0,0 @@ -/** - * Copyright (c) 2010-2024 Contributors to the openHAB project - * - * See the NOTICE file(s) distributed with this work for additional - * information. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License 2.0 which is available at - * http://www.eclipse.org/legal/epl-2.0 - * - * SPDX-License-Identifier: EPL-2.0 - */ -package org.openhab.automation.jsscripting.internal.scriptengine; - -import java.io.Reader; -import java.lang.reflect.UndeclaredThrowableException; - -import javax.script.Bindings; -import javax.script.Invocable; -import javax.script.ScriptContext; -import javax.script.ScriptEngine; -import javax.script.ScriptException; - -/** - * Delegate allowing AOP-style interception of calls, either before Invocation, or upon a {@link ScriptException}. - * being thrown. - * - * @param The delegate class - * @author Jonathan Gilbert - Initial contribution - */ -public abstract class InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable - extends DelegatingScriptEngineWithInvocableAndAutocloseable { - - public InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable(T delegate) { - super(delegate); - } - - protected void beforeInvocation() { - } - - protected Object afterInvocation(Object obj) { - return obj; - } - - protected Exception afterThrowsInvocation(Exception e) { - return e; - } - - @Override - public Object eval(String s, ScriptContext scriptContext) throws ScriptException { - try { - beforeInvocation(); - return afterInvocation(super.eval(s, scriptContext)); - } catch (ScriptException se) { - throw (ScriptException) afterThrowsInvocation(se); - } catch (Exception e) { - throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions - } - } - - @Override - public Object eval(Reader reader, ScriptContext scriptContext) throws ScriptException { - try { - beforeInvocation(); - return afterInvocation(super.eval(reader, scriptContext)); - } catch (ScriptException se) { - throw (ScriptException) afterThrowsInvocation(se); - } catch (Exception e) { - throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions - } - } - - @Override - public Object eval(String s) throws ScriptException { - try { - beforeInvocation(); - return afterInvocation(super.eval(s)); - } catch (ScriptException se) { - throw (ScriptException) afterThrowsInvocation(se); - } catch (Exception e) { - throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions - } - } - - @Override - public Object eval(Reader reader) throws ScriptException { - try { - beforeInvocation(); - return afterInvocation(super.eval(reader)); - } catch (ScriptException se) { - throw (ScriptException) afterThrowsInvocation(se); - } catch (Exception e) { - throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions - } - } - - @Override - public Object eval(String s, Bindings bindings) throws ScriptException { - try { - beforeInvocation(); - return afterInvocation(super.eval(s, bindings)); - } catch (ScriptException se) { - throw (ScriptException) afterThrowsInvocation(se); - } catch (Exception e) { - throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions - } - } - - @Override - public Object eval(Reader reader, Bindings bindings) throws ScriptException { - try { - beforeInvocation(); - return afterInvocation(super.eval(reader, bindings)); - } catch (ScriptException se) { - throw (ScriptException) afterThrowsInvocation(se); - } catch (Exception e) { - throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions - } - } - - @Override - public Object invokeMethod(Object o, String s, Object... objects) - throws ScriptException, NoSuchMethodException, NullPointerException, IllegalArgumentException { - try { - beforeInvocation(); - return afterInvocation(super.invokeMethod(o, s, objects)); - } catch (ScriptException se) { - throw (ScriptException) afterThrowsInvocation(se); - } catch (NoSuchMethodException e) { // Make sure to unlock on exceptions from Invocable.invokeMethod to avoid - // deadlocks - throw (NoSuchMethodException) afterThrowsInvocation(e); - } catch (NullPointerException e) { - throw (NullPointerException) afterThrowsInvocation(e); - } catch (IllegalArgumentException e) { - throw (IllegalArgumentException) afterThrowsInvocation(e); - } catch (Exception e) { - throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions - } - } - - @Override - public Object invokeFunction(String s, Object... objects) - throws ScriptException, NoSuchMethodException, NullPointerException { - try { - beforeInvocation(); - return afterInvocation(super.invokeFunction(s, objects)); - } catch (ScriptException se) { - throw (ScriptException) afterThrowsInvocation(se); - } catch (NoSuchMethodException e) { // Make sure to unlock on exceptions from Invocable.invokeFunction to avoid - // deadlocks - throw (NoSuchMethodException) afterThrowsInvocation(e); - } catch (NullPointerException e) { - throw (NullPointerException) afterThrowsInvocation(e); - } catch (Exception e) { - throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions - } - } -} diff --git a/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/scriptengine/InvocationInterceptingScriptEngineWithInvocableAndCompilableAndAutoCloseable.java b/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/scriptengine/InvocationInterceptingScriptEngineWithInvocableAndCompilableAndAutoCloseable.java new file mode 100644 index 0000000000..d23a5fc135 --- /dev/null +++ b/bundles/org.openhab.automation.jsscripting/src/main/java/org/openhab/automation/jsscripting/internal/scriptengine/InvocationInterceptingScriptEngineWithInvocableAndCompilableAndAutoCloseable.java @@ -0,0 +1,184 @@ +/** + * Copyright (c) 2010-2024 Contributors to the openHAB project + * + * See the NOTICE file(s) distributed with this work for additional + * information. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * http://www.eclipse.org/legal/epl-2.0 + * + * SPDX-License-Identifier: EPL-2.0 + */ +package org.openhab.automation.jsscripting.internal.scriptengine; + +import java.io.Reader; +import java.lang.reflect.UndeclaredThrowableException; + +import javax.script.Bindings; +import javax.script.Compilable; +import javax.script.CompiledScript; +import javax.script.Invocable; +import javax.script.ScriptContext; +import javax.script.ScriptEngine; +import javax.script.ScriptException; + +/** + * Delegate allowing AOP-style interception of calls, either before Invocation, or upon a {@link ScriptException} being + * thrown. + * + * @param The delegate class + * @author Jonathan Gilbert - Initial contribution + */ +public abstract class InvocationInterceptingScriptEngineWithInvocableAndCompilableAndAutoCloseable + extends DelegatingScriptEngineWithInvocableAndCompilableAndAutocloseable { + + public InvocationInterceptingScriptEngineWithInvocableAndCompilableAndAutoCloseable(T delegate) { + super(delegate); + } + + protected void beforeInvocation() { + } + + protected Object afterInvocation(Object obj) { + return obj; + } + + protected Exception afterThrowsInvocation(Exception e) { + return e; + } + + @Override + public Object eval(String s, ScriptContext scriptContext) throws ScriptException { + try { + beforeInvocation(); + return afterInvocation(super.eval(s, scriptContext)); + } catch (ScriptException se) { + throw (ScriptException) afterThrowsInvocation(se); + } catch (Exception e) { + throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions + } + } + + @Override + public Object eval(Reader reader, ScriptContext scriptContext) throws ScriptException { + try { + beforeInvocation(); + return afterInvocation(super.eval(reader, scriptContext)); + } catch (ScriptException se) { + throw (ScriptException) afterThrowsInvocation(se); + } catch (Exception e) { + throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions + } + } + + @Override + public Object eval(String s) throws ScriptException { + try { + beforeInvocation(); + return afterInvocation(super.eval(s)); + } catch (ScriptException se) { + throw (ScriptException) afterThrowsInvocation(se); + } catch (Exception e) { + throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions + } + } + + @Override + public Object eval(Reader reader) throws ScriptException { + try { + beforeInvocation(); + return afterInvocation(super.eval(reader)); + } catch (ScriptException se) { + throw (ScriptException) afterThrowsInvocation(se); + } catch (Exception e) { + throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions + } + } + + @Override + public Object eval(String s, Bindings bindings) throws ScriptException { + try { + beforeInvocation(); + return afterInvocation(super.eval(s, bindings)); + } catch (ScriptException se) { + throw (ScriptException) afterThrowsInvocation(se); + } catch (Exception e) { + throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions + } + } + + @Override + public Object eval(Reader reader, Bindings bindings) throws ScriptException { + try { + beforeInvocation(); + return afterInvocation(super.eval(reader, bindings)); + } catch (ScriptException se) { + throw (ScriptException) afterThrowsInvocation(se); + } catch (Exception e) { + throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions + } + } + + @Override + public Object invokeMethod(Object o, String s, Object... objects) + throws ScriptException, NoSuchMethodException, NullPointerException, IllegalArgumentException { + try { + beforeInvocation(); + return afterInvocation(super.invokeMethod(o, s, objects)); + } catch (ScriptException se) { + throw (ScriptException) afterThrowsInvocation(se); + } catch (NoSuchMethodException e) { // Make sure to unlock on exceptions from Invocable.invokeMethod to avoid + // deadlocks + throw (NoSuchMethodException) afterThrowsInvocation(e); + } catch (NullPointerException e) { + throw (NullPointerException) afterThrowsInvocation(e); + } catch (IllegalArgumentException e) { + throw (IllegalArgumentException) afterThrowsInvocation(e); + } catch (Exception e) { + throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions + } + } + + @Override + public Object invokeFunction(String s, Object... objects) + throws ScriptException, NoSuchMethodException, NullPointerException { + try { + beforeInvocation(); + return afterInvocation(super.invokeFunction(s, objects)); + } catch (ScriptException se) { + throw (ScriptException) afterThrowsInvocation(se); + } catch (NoSuchMethodException e) { // Make sure to unlock on exceptions from Invocable.invokeFunction to avoid + // deadlocks + throw (NoSuchMethodException) afterThrowsInvocation(e); + } catch (NullPointerException e) { + throw (NullPointerException) afterThrowsInvocation(e); + } catch (Exception e) { + throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions + } + } + + @Override + public CompiledScript compile(String s) throws ScriptException { + try { + beforeInvocation(); + return (CompiledScript) afterInvocation(super.compile(s)); + } catch (ScriptException se) { + throw (ScriptException) afterThrowsInvocation(se); + } catch (Exception e) { + throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions + } + } + + @Override + public CompiledScript compile(Reader reader) throws ScriptException { + try { + beforeInvocation(); + return (CompiledScript) afterInvocation(super.compile(reader)); + } catch (ScriptException se) { + throw (ScriptException) afterThrowsInvocation(se); + } catch (Exception e) { + throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions + } + } +} diff --git a/bundles/org.openhab.automation.jsscripting/suppressions.properties b/bundles/org.openhab.automation.jsscripting/suppressions.properties index 38e9aa4cf1..11aad04ecb 100644 --- a/bundles/org.openhab.automation.jsscripting/suppressions.properties +++ b/bundles/org.openhab.automation.jsscripting/suppressions.properties @@ -1,3 +1,3 @@ # Please check here how to add suppressions https://maven.apache.org/plugins/maven-pmd-plugin/examples/violation-exclusions.html org.openhab.automation.jsscripting.internal.OpenhabGraalJSScriptEngine=UnusedPrivateField -org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocableAndAutoCloseable=AvoidThrowingNullPointerException,AvoidCatchingNPE +org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocableAndCompilableAndAutoCloseable=AvoidThrowingNullPointerException,AvoidCatchingNPE