From 23feb8f42958b45a95c369eb95eee4541586ea19 Mon Sep 17 00:00:00 2001 From: Matthew Burgess Date: Wed, 23 May 2018 09:52:33 -0400 Subject: [PATCH] NIFI-5230: Fixed NPE in InvokeScriptedProcessor on customValidate This closes #2734 Signed-off-by: Mike Thomsen --- .../processors/script/InvokeScriptedProcessor.java | 4 ++-- .../nifi/processors/script/TestInvokeGroovy.java | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 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 5805d85d55..45439bf36f 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 @@ -237,7 +237,7 @@ public class InvokeScriptedProcessor extends AbstractSessionFactoryProcessor { @Override public void onPropertyModified(final PropertyDescriptor descriptor, final String oldValue, final String newValue) { - validationResults.set(null); + validationResults.set(new HashSet<>()); final ComponentLog logger = getLogger(); final Processor instance = processor.get(); @@ -455,7 +455,7 @@ public class InvokeScriptedProcessor extends AbstractSessionFactoryProcessor { // do not try to build processor/compile/etc until onPropertyModified clear the validation error/s // and don't print anything into log. - if (validationResults.get() != null){ + if (!validationResults.get().isEmpty()) { return validationResults.get(); } diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeGroovy.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeGroovy.java index 7568a04b5c..4a17c8ade6 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeGroovy.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeGroovy.java @@ -50,7 +50,6 @@ public class TestInvokeGroovy extends BaseScriptTest { */ @Test public void testReadFlowFileContentAndStoreInFlowFileAttribute() throws Exception { - runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/groovy/test_reader.groovy"); runner.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/groovy"); @@ -140,7 +139,6 @@ public class TestInvokeGroovy extends BaseScriptTest { @Test(expected = AssertionError.class) public void testInvokeScriptCausesException() throws Exception { final TestRunner runner = TestRunners.newTestRunner(new InvokeScriptedProcessor()); - runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString( TEST_RESOURCE_LOCATION + "groovy/testInvokeScriptCausesException.groovy") @@ -158,7 +156,6 @@ public class TestInvokeGroovy extends BaseScriptTest { */ @Test public void testScriptRoutesToFailure() throws Exception { - runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString( TEST_RESOURCE_LOCATION + "groovy/testScriptRoutesToFailure.groovy") @@ -171,4 +168,15 @@ public class TestInvokeGroovy extends BaseScriptTest { final List result = runner.getFlowFilesForRelationship("FAILURE"); assertFalse(result.isEmpty()); } + + @Test + public void testValidationResultsReset() throws Exception { + runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); + runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/groovy/test_reader.groovy"); + runner.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/groovy"); + + runner.assertValid(); + runner.setProperty("test-attribute", "test"); + runner.assertValid(); + } }