Skip to content

Commit 2c44ddd

Browse files
committed
fix GraalVM close for compiled scripts
1 parent 9f3b7c9 commit 2c44ddd

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

bundles/org.openhab.automation.pythonscripting/src/main/java/org/openhab/automation/pythonscripting/internal/scriptengine/InvocationInterceptingScriptEngineWithInvocableAndCompilableAndAutoCloseable.java

+16-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public Object invokeFunction(String s, Object... objects)
165165
@Override
166166
public CompiledScript compile(String s) throws ScriptException {
167167
try {
168-
return (CompiledScript) afterInvocation(super.compile(beforeInvocation(s)));
168+
return wrapCompiledScript((CompiledScript) afterInvocation(super.compile(beforeInvocation(s))));
169169
} catch (ScriptException se) {
170170
throw (ScriptException) afterThrowsInvocation(se);
171171
} catch (Exception e) {
@@ -176,11 +176,25 @@ public CompiledScript compile(String s) throws ScriptException {
176176
@Override
177177
public CompiledScript compile(Reader reader) throws ScriptException {
178178
try {
179-
return (CompiledScript) afterInvocation(super.compile(beforeInvocation(reader)));
179+
return wrapCompiledScript((CompiledScript) afterInvocation(super.compile(beforeInvocation(reader))));
180180
} catch (ScriptException se) {
181181
throw (ScriptException) afterThrowsInvocation(se);
182182
} catch (Exception e) {
183183
throw new UndeclaredThrowableException(afterThrowsInvocation(e)); // Wrap and rethrow other exceptions
184184
}
185185
}
186+
187+
private CompiledScript wrapCompiledScript(CompiledScript script) throws ScriptException {
188+
return new CompiledScript() {
189+
@Override
190+
public ScriptEngine getEngine() {
191+
return InvocationInterceptingScriptEngineWithInvocableAndCompilableAndAutoCloseable.this;
192+
}
193+
194+
@Override
195+
public Object eval(ScriptContext context) throws ScriptException {
196+
return script.eval(context);
197+
}
198+
};
199+
}
186200
}

0 commit comments

Comments
 (0)