A better way to handle no Routines

In some sample code from ST they get the list of Routines/Phrases in this manner:

def phrases = location.helloHome?.getPhrases()*.label

A system in which there are no routines, getPhrases() would return null. Now I know that the spread dot operator is null safe, but I don’t think it’ll work on a null object, it’ll just ignore element in an array.

Am I correct? If so maybe ST should change the sample code

Wouldn’t the ?.getPhrases() be ok due to the ?. safe navigation?

I have a feeling getPhrases() is returning null and helloHome isn’t.

ie. it would be akin to (null)*.label where as *. is a safe navigator and will be able to handle [null]*.label but not the former if I’m correct.

You can run a quick test here:

This works:

def t = [[name:“test”, label:“joke”], null]

This doesn’t

def t = null