mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-10 21:31:53 +01:00
[automation] Fixed memory leak caused by invalid UI DSL rule (#2212)
Signed-off-by: Mark Hilbush <mark@hilbush.com>
This commit is contained in:
parent
c7b7390c91
commit
7de57f9ffe
@ -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<Diagnostic> errors = resource.getErrors();
|
||||
if (!errors.isEmpty()) {
|
||||
deleteResource(resource);
|
||||
throw new ScriptParsingException("Failed to parse expression (due to managed SyntaxError/s)",
|
||||
scriptAsString).addDiagnosticErrors(errors);
|
||||
}
|
||||
|
||||
EList<EObject> contents = resource.getContents();
|
||||
|
||||
if (!contents.isEmpty()) {
|
||||
Iterable<Issue> 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user