Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

Does any one know why or under what circumstances NIFI passes a null flowfile to a custom NIFI processor ?

Solved Go to solution

Does any one know why or under what circumstances NIFI passes a null flowfile to a custom NIFI processor ?

New Contributor

Does any one know why or under what circumstances NIFI passes a null flowfile to a custom NIFI processor ? We are seeing cases where the session that is passed in as an input to the onTrigger method of the custom (java) processor contains a session with a null flow file. Is this a normal condition ? We are treating it as an error case and logging it as an error. (Not sure if this is the correct thing to do.

The following code inside of the custom processor's "onTrigger" method is returning a null flow file.

FlowFile flowFile = session.get();

if (flowFile == null) {

getLogger().error("End Invocation - Failure " + className + "Instance HashCode: " + hashCode + " onTrigger operation. Got null flowflile from session " + sessionHashCode +" and returning control to NIFI at " + System.currentTimeMillis()); return;

}

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Does any one know why or under what circumstances NIFI passes a null flowfile to a custom NIFI processor ?

This is normal behavior, typically you just call session.get() and if the flow file returned is null then just return from the processor:

https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-proce...

The most common reason for this is when concurrent tasks is set to more than 1 for a processor with an input queue. In this case, the framework might trigger both threads to execute, but thread 1 might grab the only flow file, or all the available flow files, and by the time thread 2 executes there is nothing left.

3 REPLIES 3

Re: Does any one know why or under what circumstances NIFI passes a null flowfile to a custom NIFI processor ?

This is normal behavior, typically you just call session.get() and if the flow file returned is null then just return from the processor:

https://github.com/apache/nifi/blob/master/nifi-nar-bundles/nifi-standard-bundle/nifi-standard-proce...

The most common reason for this is when concurrent tasks is set to more than 1 for a processor with an input queue. In this case, the framework might trigger both threads to execute, but thread 1 might grab the only flow file, or all the available flow files, and by the time thread 2 executes there is nothing left.

Highlighted

Re: Does any one know why or under what circumstances NIFI passes a null flowfile to a custom NIFI processor ?

New Contributor

I got the same "issue" and that is exactly the case for multiple threads.

Thanks,

Mark

Re: Does any one know why or under what circumstances NIFI passes a null flowfile to a custom NIFI processor ?

Super Guru

It's Java, if you aren't expecting nulls. Expect crashes.

First Rule of Java, Handle Nulls.

Second Rule of Java, Handle Exceptions because you forgot 1st rule.