Check if object is null before executing for

You have not disclosed what resource is appearing in the plan snippet, so it is difficult to guess what is going on.

My hunch is that the nulls are there because that is how the resource type involved works, and cannot be removed.