Is an empty branch invalid and/or null?

Continuing from a somewhat similar topic here:

I just came across this behaviour again and every time it doesn’t make sense to me.

If I test an empty branch if it is invalid or null using Null Item, it tells me it is both invalid and null. Yet Replace Nulls does nothing on empty branches.

So which one is wrong? Or how can I check for empty branches. I am aware of the workaround posted in the link, but I want to understand the reasoning.

Couldn’t the Null Item have another output for empty and have at least the Null output set to false? Maybe its just down to wording, but the Replace Null’s description sounds like what it is doing is check for Null using the Null Item and if that is true replace it with whatever is plugged in. But that’s not what it does at all. It somehow uses another check to see if something is ONLY null or invalid. Very confusing. (5.9 KB)

A List containing zero elements does not contains a null element, it’s still a valid list with length= zero.
In grasshopper you can address this kind of problems almost always easily… if you can be more specific of what is your case it will be easier to build up a proper solution.

I usually check if the list (or branch) length is greater than zero, if yes I do something, if not i do something else…
Then, if you have a non-empty list, it’s unlikely to have completely “missing objects” mixed with valid objects, more probably you’ll have actual [Null] objects mixed with valid objects.

That’s exactly my issue. According to the Null Item an empty list is Invalid:

I said “valid List”, not valid object.
The list is valid but empty.

Again, that specific case in your picture might seems incorrect, but managing nulls, empty lists, invalid objects, and so on, is not that a hassle in grasshopper.
Can you post a case where this is causing you problems?

It’s okay, it works fine with the fix from the link with Combine Data before Replace Nulls, so it changes all empties to nulls. Basically I have 2 states: either there is a tree with data or no data at all. Since it is a scaling factor it can’t be empty, so I want to replace the empty list with 1 in that case. In rare cases the tree can also contain empty branches and in those I need to put 1 as well.

It seemed logical that Replace Nulls can do that since Null Item tells me the item is invalid. So yeah, Combine Data before Replace Nulls makes it work.

I just find it weird, but I guess its down to wording. You are talking about “lists” and “objects”, while Replace Nulls speaks of “data” and Null Item speaks of “items”. They sound very similar but obviously mean different things…

If that’s the case you might consider using multiplication:

As a general note, it is not possible for lists or trees to be invalid or null. They can at most be empty.

It looks like the null item component has a bug.