[ https://issues.apache.org/jira/browse/GROOVY-7177?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles updated GROOVY-7177: -------------------------------- Description: {code:groovy} def someCollection = null someCollection.collect { e -> e.name } // returns [] someCollection*.name // returns null (or [] for SC) someCollection.name // throws NullPointerException {code} Actual: {{someCollection}} is null, with no typing hints as to what {{someCollection}} really is, and yet it invokes {{.collect()}} on a null reference. How is that possible without collect being a global function? Expected: All 3 situations throw a NPE. The spread operator seems to short circuit nulls like the ?. operator. So really the spread operator is more like ?.* operator which is maybe desirable. But it's not explicit that it does that and is a bit surprising given we have the difference of . and ?. At the least this is inconsistent between these various operations. was: {code} def someCollection = null someCollection.collect { x -> x.name } // returns [] someCollection.*name // returns null someCollection.name // throws NPE {code} Actual: someCollection is null, with no typing hints as to what someCollection really is, and yet it invokes .collect() on a null reference. How is that possible without collect being a global function? Expected: All 3 situations throw a NPE. The spread operator seems to short circuit nulls like the ?. operator. So really the spread operator is more like ?.* operator which is maybe desirable. But it's not explicit that it does that and is a bit surprising given we have the difference of . and ?. At the least this is inconsistent between these various operations. > Calling collect on null doesn't result in a NPE > ----------------------------------------------- > > Key: GROOVY-7177 > URL: https://issues.apache.org/jira/browse/GROOVY-7177 > Project: Groovy > Issue Type: Bug > Components: groovy-runtime > Affects Versions: 2.3.7 > Reporter: Charlie Hubbard > Priority: Major > > {code:groovy} > def someCollection = null > someCollection.collect { e -> e.name } // returns [] > someCollection*.name // returns null (or [] for SC) > someCollection.name // throws NullPointerException > {code} > Actual: > {{someCollection}} is null, with no typing hints as to what > {{someCollection}} really is, and yet it invokes {{.collect()}} on a null > reference. How is that possible without collect being a global function? > Expected: > All 3 situations throw a NPE. The spread operator seems to short circuit > nulls like the ?. operator. So really the spread operator is more like ?.* > operator which is maybe desirable. But it's not explicit that it does that > and is a bit surprising given we have the difference of . and ?. At the least > this is inconsistent between these various operations. -- This message was sent by Atlassian Jira (v8.20.10#820010)