NIFI-5230: Fixed NPE in InvokeScriptedProcessor on customValidate

This closes #2734

Signed-off-by: Mike Thomsen <mikerthomsen@gmail.com>
This commit is contained in:
Matthew Burgess 2018-05-23 09:52:33 -04:00 committed by Mike Thomsen
parent 3a29c1e4ca
commit 23feb8f429
2 changed files with 13 additions and 5 deletions

View File

@ -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();
}

View File

@ -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<MockFlowFile> 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();
}
}