From cb275dd956010be6e43ecf7090981b20a1fc2180 Mon Sep 17 00:00:00 2001 From: Mark Payne Date: Mon, 22 Aug 2022 16:54:03 -0400 Subject: [PATCH] NIFI-10385: If script body is empty for AbstractScriptedControllerService or InvokeScriptedProcessor, do not attempt to load script Signed-off-by: Matthew Burgess This closes #6324 --- .../processors/script/InvokeScriptedProcessor.java | 10 ++++++++-- .../script/AbstractScriptedControllerService.java | 11 +++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/InvokeScriptedProcessor.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/InvokeScriptedProcessor.java index d5172be8a7..5cc4d65861 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/InvokeScriptedProcessor.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/processors/script/InvokeScriptedProcessor.java @@ -282,11 +282,14 @@ public class InvokeScriptedProcessor extends AbstractSessionFactoryProcessor { * @return true if the script was loaded successfully; false otherwise */ private boolean reloadScriptFile(final String scriptPath) { + if (StringUtils.isEmpty(scriptPath)) { + return false; + } + final Collection results = new HashSet<>(); try (final FileInputStream scriptStream = new FileInputStream(scriptPath)) { return reloadScript(IOUtils.toString(scriptStream, Charset.defaultCharset())); - } catch (final Exception e) { final ComponentLog logger = getLogger(); final String message = "Unable to load script: " + e; @@ -314,10 +317,13 @@ public class InvokeScriptedProcessor extends AbstractSessionFactoryProcessor { * @return true if the script was loaded successfully; false otherwise */ private boolean reloadScriptBody(final String scriptBody) { + if (StringUtils.isEmpty(scriptBody)) { + return false; + } + final Collection results = new HashSet<>(); try { return reloadScript(scriptBody); - } catch (final Exception e) { final ComponentLog logger = getLogger(); final String message = "Unable to load script: " + e; diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/script/AbstractScriptedControllerService.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/script/AbstractScriptedControllerService.java index 1cdcb809e2..71157cae74 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/script/AbstractScriptedControllerService.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/main/java/org/apache/nifi/script/AbstractScriptedControllerService.java @@ -27,6 +27,7 @@ import org.apache.nifi.expression.ExpressionLanguageScope; import org.apache.nifi.logging.ComponentLog; import org.apache.nifi.processor.util.StandardValidators; import org.apache.nifi.processors.script.ScriptRunner; +import org.apache.nifi.util.StringUtils; import java.io.FileInputStream; import java.nio.charset.Charset; @@ -158,11 +159,14 @@ public abstract class AbstractScriptedControllerService extends AbstractControll * @return true if the script was loaded successfully; false otherwise */ protected boolean reloadScriptFile(final String scriptPath) { + if (StringUtils.isEmpty(scriptPath)) { + return false; + } + final Collection results = new HashSet<>(); try (final FileInputStream scriptStream = new FileInputStream(scriptPath)) { return reloadScript(IOUtils.toString(scriptStream, Charset.defaultCharset())); - } catch (final Exception e) { final ComponentLog logger = getLogger(); final String message = "Unable to load script: " + e; @@ -190,10 +194,13 @@ public abstract class AbstractScriptedControllerService extends AbstractControll * @return true if the script was loaded successfully; false otherwise */ protected boolean reloadScriptBody(final String scriptBody) { + if (StringUtils.isEmpty(scriptBody)) { + return false; + } + final Collection results = new HashSet<>(); try { return reloadScript(scriptBody); - } catch (final Exception e) { final ComponentLog logger = getLogger(); final String message = "Unable to load script: " + e;