Sorry for the late reply, I can only work on my home automation on weekends…
The group GassociatedCounters consists of static items only, as well as the groups in the triggeringItem, so I wonder how they could be null. I’ve now implemented a check for invalid casts by verifying groupItem !== null.
But I think I’m missing your point. I stumbled about Is there a difference between null and NULL?.
I guess you mean that
var count = groupItem.allMembers.filter(l|(l.state > 0 || l.state==ON)).size
does not work in all cases. Do you say it will fail if state is NULL? Should it be like this:
var count = groupItem.allMembers.filter(l|((l.state != NULL) && (l.state > 0 || l.state==ON))).size