NIFI-9389 - NPE guard for ExecuteProcess on no OnTriggered

NIFI-9389 - NPE guard for ExecuteProcess on no OnTriggered
This commit is contained in:
Paul Grey 2021-11-19 14:34:57 -05:00 committed by Joe Witt
parent 87ef4deb9c
commit bb0696645e
No known key found for this signature in database
GPG Key ID: 9093BF854F811A1A
3 changed files with 13 additions and 2 deletions

View File

@ -187,7 +187,7 @@ public class StandardProcessorTestRunner implements TestRunner {
@Override
public void run(final int iterations, final boolean stopOnFinish, final boolean initialize, final long runWait) {
if (iterations < 1) {
if (iterations < 0) {
throw new IllegalArgumentException();
}

View File

@ -207,7 +207,7 @@ public class ExecuteProcess extends AbstractProcessor {
try {
executor.shutdown();
} finally {
if (this.externalProcess.isAlive()) {
if ((this.externalProcess != null) && (this.externalProcess.isAlive())) {
this.getLogger().info("Process hasn't terminated, forcing the interrupt");
this.externalProcess.destroyForcibly();
}

View File

@ -313,4 +313,15 @@ public class TestExecuteProcess {
.anyMatch(m -> m.getMsg().contains("Failed to create process due to")));
}
/**
* On configuration of this processor to run only on primary cluster node, other nodes call
* {@link org.apache.nifi.annotation.lifecycle.OnUnscheduled} method after an invocation (Start/Stop or RunOnce),
* causing an NPE. NPE guard added; test for this situation.
*/
@Test
public void testProcessorNotScheduled() {
final TestRunner runner = TestRunners.newTestRunner(ExecuteProcess.class);
runner.setProperty(ExecuteProcess.COMMAND, "ls");
runner.run(0);
}
}