[ 
https://issues.apache.org/jira/browse/GROOVY-7177?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17875894#comment-17875894
 ] 

Eric Milles commented on GROOVY-7177:
-------------------------------------

{{a*.b}} is spread-safe operator.  This means it is null-safe.  It is expected 
to get the null result instead of a NullPointerException.  The difference 
between dynamic and static compilation is discussed in GROOVY-11453.

> 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)

Reply via email to