You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Ralph Johnson <jo...@cs.uiuc.edu> on 2015/11/17 20:04:45 UTC
change in definition of Groovy?
I am in the process of converting a large Groovy program from 2.1 to 2.4.
A year or two ago I converted it from (I think) 1.8 to 2.1.
I found an odd assignment.
obj.foo?.fee = v
The code assumed that if obj.foo was null, this assignment statement was
skipped. It does not work that way in 2.4, and I had to rewrite it to
make the code work. I had no idea that you could use the safe
dereferencing operator on the left-hand-side of an assignment, I always
thought it was only on the right-hand-side. I imagine that the author of
this code was exploiting a bug in Groovy, that Groovy was never supposed to
allow this. Somewhere between 2.1 and 2.4, this bug got fixed. Or was
there a change in the definition of Groovy? Or am I completely missing
the point?
-Ralph Johnson
Re: change in definition of Groovy?
Posted by Ralph Johnson <jo...@cs.uiuc.edu>.
Thanks for your reply! I had made (and tested) a fix before sending the
mail, but apparently the bug wasn't what I thought it was. So, I'll have
to dig deeper.
-Ralph
On Tue, Nov 17, 2015 at 2:39 PM, Tankerbay <ta...@gmail.com> wrote:
> +1 for sdkman.io!
>
> Sent from my phone. Please excuse the mess.
> On Nov 17, 2015 11:16 AM, "Søren Berg Glasius" <so...@glasius.dk> wrote:
>
>> Hi Ralph,
>>
>> Had to fire up Groovy Console (2.4.5) and try it out:
>>
>> class Obj {
>> Map foo
>> }
>>
>> obj = new Obj()
>>
>> obj.foo?.fee = 'some value'
>>
>> assert obj.foo?.fee == null
>>
>> I do not see an error, so unless I misunderstand your problem, I do not
>> think it's wrong.
>>
>> To verify, I did the same with Groovy 2.1.9, same result. Then with
>> Groovy 1.8.9, just to be sure, also same result.
>>
>> PS: Just got to love sdkman.io when testing such code....
>>
>> Best regards / Med venlig hilsen,
>> Søren Berg Glasius
>>
>> Hedevej 1, Gl. Rye, 8680 Ry, Denmark
>> Mobile: +45 40 44 91 88, Skype: sbglasius
>> --- Press ESC once to quit - twice to save the changes.
>>
>> On November 17, 2015 at 8:04:55 PM, Ralph Johnson (johnson@cs.uiuc.edu)
>> wrote:
>>
>> I am in the process of converting a large Groovy program from 2.1 to 2.4.
>> A year or two ago I converted it from (I think) 1.8 to 2.1.
>>
>> I found an odd assignment.
>>
>> obj.foo?.fee = v
>>
>> The code assumed that if obj.foo was null, this assignment statement was
>> skipped. It does not work that way in 2.4, and I had to rewrite it to
>> make the code work. I had no idea that you could use the safe
>> dereferencing operator on the left-hand-side of an assignment, I always
>> thought it was only on the right-hand-side. I imagine that the author of
>> this code was exploiting a bug in Groovy, that Groovy was never supposed to
>> allow this. Somewhere between 2.1 and 2.4, this bug got fixed. Or was
>> there a change in the definition of Groovy? Or am I completely missing
>> the point?
>>
>> -Ralph Johnson
>>
>>
Re: change in definition of Groovy?
Posted by Tankerbay <ta...@gmail.com>.
+1 for sdkman.io!
Sent from my phone. Please excuse the mess.
On Nov 17, 2015 11:16 AM, "Søren Berg Glasius" <so...@glasius.dk> wrote:
> Hi Ralph,
>
> Had to fire up Groovy Console (2.4.5) and try it out:
>
> class Obj {
> Map foo
> }
>
> obj = new Obj()
>
> obj.foo?.fee = 'some value'
>
> assert obj.foo?.fee == null
>
> I do not see an error, so unless I misunderstand your problem, I do not
> think it's wrong.
>
> To verify, I did the same with Groovy 2.1.9, same result. Then with Groovy
> 1.8.9, just to be sure, also same result.
>
> PS: Just got to love sdkman.io when testing such code....
>
> Best regards / Med venlig hilsen,
> Søren Berg Glasius
>
> Hedevej 1, Gl. Rye, 8680 Ry, Denmark
> Mobile: +45 40 44 91 88, Skype: sbglasius
> --- Press ESC once to quit - twice to save the changes.
>
> On November 17, 2015 at 8:04:55 PM, Ralph Johnson (johnson@cs.uiuc.edu)
> wrote:
>
> I am in the process of converting a large Groovy program from 2.1 to 2.4.
> A year or two ago I converted it from (I think) 1.8 to 2.1.
>
> I found an odd assignment.
>
> obj.foo?.fee = v
>
> The code assumed that if obj.foo was null, this assignment statement was
> skipped. It does not work that way in 2.4, and I had to rewrite it to
> make the code work. I had no idea that you could use the safe
> dereferencing operator on the left-hand-side of an assignment, I always
> thought it was only on the right-hand-side. I imagine that the author of
> this code was exploiting a bug in Groovy, that Groovy was never supposed to
> allow this. Somewhere between 2.1 and 2.4, this bug got fixed. Or was
> there a change in the definition of Groovy? Or am I completely missing
> the point?
>
> -Ralph Johnson
>
>
Re: change in definition of Groovy?
Posted by Søren Berg Glasius <so...@glasius.dk>.
Hi Ralph,
Had to fire up Groovy Console (2.4.5) and try it out:
class Obj {
Map foo
}
obj = new Obj()
obj.foo?.fee = 'some value'
assert obj.foo?.fee == null
I do not see an error, so unless I misunderstand your problem, I do not think it's wrong.
To verify, I did the same with Groovy 2.1.9, same result. Then with Groovy 1.8.9, just to be sure, also same result.
PS: Just got to love sdkman.io when testing such code....
Best regards / Med venlig hilsen,
Søren Berg Glasius
Hedevej 1, Gl. Rye, 8680 Ry, Denmark
Mobile: +45 40 44 91 88, Skype: sbglasius
--- Press ESC once to quit - twice to save the changes.
On November 17, 2015 at 8:04:55 PM, Ralph Johnson (johnson@cs.uiuc.edu) wrote:
I am in the process of converting a large Groovy program from 2.1 to 2.4. A year or two ago I converted it from (I think) 1.8 to 2.1.
I found an odd assignment.
obj.foo?.fee = v
The code assumed that if obj.foo was null, this assignment statement was skipped. It does not work that way in 2.4, and I had to rewrite it to make the code work. I had no idea that you could use the safe dereferencing operator on the left-hand-side of an assignment, I always thought it was only on the right-hand-side. I imagine that the author of this code was exploiting a bug in Groovy, that Groovy was never supposed to allow this. Somewhere between 2.1 and 2.4, this bug got fixed. Or was there a change in the definition of Groovy? Or am I completely missing the point?
-Ralph Johnson