ajwang / groovypptest

Automatically exported from code.google.com/p/groovypptest
0 stars 0 forks source link

Inconsistent handling of iterating over a null collection #346

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
In the code below, at point 1), iterating over a null collection works, but at 
point 2) it throw an NPE.

It's inconsistent here. In core Groovy, each usage works as a no-op without NPE.
------------------------------------
@Typed 
class Dummy {
    static void main(args) {
        new Dummy().foo()
    }
    def foo() {
        List nullList = null
        nullList.each{} /* 1 */
        bar(nullList)
    }
    def bar(List list) {
        list.each{} /* 2 */
    }
}
------------------------------------

Original issue reported on code.google.com by roshanda...@gmail.com on 8 Mar 2011 at 5:04

GoogleCodeExporter commented 8 years ago
Even if I change it to 

list?.each{} /* 2 */

I get an NPE.

Original comment by roshanda...@gmail.com on 8 Mar 2011 at 8:59

GoogleCodeExporter commented 8 years ago
Probably fixed in 0.4.174

Original comment by alex.tka...@gmail.com on 8 Mar 2011 at 6:54

GoogleCodeExporter commented 8 years ago
Verified. 

Works perfect with the reported usage as well as a few others that I had later 
found out. 

Thanks.

Original comment by roshanda...@gmail.com on 9 Mar 2011 at 2:59