diff --git a/bundles/org.openhab.core.model.script.runtime/src/org/openhab/core/model/script/runtime/internal/engine/ScriptEngineImpl.java b/bundles/org.openhab.core.model.script.runtime/src/org/openhab/core/model/script/runtime/internal/engine/ScriptEngineImpl.java index 1c7e734ba3..b57f5691b1 100644 --- a/bundles/org.openhab.core.model.script.runtime/src/org/openhab/core/model/script/runtime/internal/engine/ScriptEngineImpl.java +++ b/bundles/org.openhab.core.model.script.runtime/src/org/openhab/core/model/script/runtime/internal/engine/ScriptEngineImpl.java @@ -14,6 +14,7 @@ package org.openhab.core.model.script.runtime.internal.engine; import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -136,21 +137,23 @@ public class ScriptEngineImpl implements ScriptEngine, ModelParser { List errors = resource.getErrors(); if (!errors.isEmpty()) { + deleteResource(resource); throw new ScriptParsingException("Failed to parse expression (due to managed SyntaxError/s)", scriptAsString).addDiagnosticErrors(errors); } EList contents = resource.getContents(); - if (!contents.isEmpty()) { Iterable validationErrors = getValidationErrors(contents.get(0)); if (!validationErrors.iterator().hasNext()) { return (XExpression) contents.get(0); } else { + deleteResource(resource); throw new ScriptParsingException("Failed to parse expression (due to managed ValidationError/s)", scriptAsString).addValidationIssues(validationErrors); } } else { + deleteResource(resource); return null; } } @@ -184,4 +187,11 @@ public class ScriptEngineImpl implements ScriptEngine, ModelParser { return "script"; } + private void deleteResource(Resource resource) { + try { + resource.delete(Collections.emptyMap()); + } catch(IOException e) { + // Do nothing + } + } }