It’s been like this for as long as I’ve been using compile static in Groovy. I assumed that was expected behavior and I make sure to point it out to all new developers in our project as one of the Groovy gotchas. Is it not supposed to be that way?

 

Jason

 

From: Paolo Di Tommaso [mailto:paolo.ditommaso@gmail.com]
Sent: Friday, December 15, 2017 2:29 AM
To: users@groovy.apache.org
Subject: Re: @CompileStatic null iteration

 

Just found the same problem. This difference can introduce subtle bugs when refactoring groovy code to CompileStatic. 

 

I suggest to report a bug for that. 

 

 

Cheers, Paolo

  

 

On Tue, Dec 12, 2017 at 12:45 AM, MG <mgbiz@arscreat.com> wrote:

Hi guys,

just a quick question since we came across it today when testing code that had been converted from dynamic to static Groovy: Is the behavior that statically compiled Groovy throws a NPE when the iterable to be iterated over is null (same as Java), while dynamically compiled Groovy uses the NullObject.iterator(), i.e. does not throw but instead iterates over an empty collection by design ?

Cheers,
mg

 

This email message and any attachments are for the sole use of the intended recipient(s). Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message and any attachments.