Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

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

avatar
Explorer

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

avatar
Master Guru

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.

View solution in original post

3 REPLIES 3

avatar
Master Guru

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.

avatar
Explorer

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

Thanks,

Mark

avatar
Master 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.