From 166e4ec1b6e487d24865d4feafd21c70e79d49b9 Mon Sep 17 00:00:00 2001 From: jimtng <2554958+jimtng@users.noreply.github.com> Date: Tue, 1 Mar 2022 03:09:57 +1000 Subject: [PATCH] [jrubyscripting] Filter out empty require options (#12386) Signed-off-by: Jimmy Tanagra --- .../JRubyScriptEngineConfiguration.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/bundles/org.openhab.automation.jrubyscripting/src/main/java/org/openhab/automation/jrubyscripting/internal/JRubyScriptEngineConfiguration.java b/bundles/org.openhab.automation.jrubyscripting/src/main/java/org/openhab/automation/jrubyscripting/internal/JRubyScriptEngineConfiguration.java index 9e8b8ea1f..d9f0e2945 100644 --- a/bundles/org.openhab.automation.jrubyscripting/src/main/java/org/openhab/automation/jrubyscripting/internal/JRubyScriptEngineConfiguration.java +++ b/bundles/org.openhab.automation.jrubyscripting/src/main/java/org/openhab/automation/jrubyscripting/internal/JRubyScriptEngineConfiguration.java @@ -198,16 +198,16 @@ public class JRubyScriptEngineConfiguration { return; } - String[] scripts = requireConfigElement.getValue().get().split(","); - for (String script : scripts) { - final String requireStatement = String.format("require '%s'", script.trim()); - try { - logger.trace("Injecting require statement: {}", requireStatement); - engine.eval(requireStatement); - } catch (ScriptException e) { - logger.warn("Error evaluating statement {}: {}", requireStatement, e.getMessage()); - } - } + Stream.of(requireConfigElement.getValue().get().split(",")).map(s -> s.trim()).filter(s -> !s.isEmpty()) + .forEach(script -> { + final String requireStatement = String.format("require '%s'", script); + try { + logger.trace("Injecting require statement: {}", requireStatement); + engine.eval(requireStatement); + } catch (ScriptException e) { + logger.warn("Error evaluating statement {}: {}", requireStatement, e.getMessage()); + } + }); } /**