groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jochen Theodorou <blackd...@gmx.org>
Subject Re: Strange behaviour with binding resolution in Groovy based DSL
Date Mon, 26 Sep 2016 08:30:11 GMT


On 26.09.2016 09:02, Michael Rüegg wrote:
> Hi,
>
> I have a Groovy based DSL in which I want to access variables from declared bindings.
Here's my DSL implementation:
>
> https://gist.github.com/MichaelRueegg/f3f09aeb5853bdb58ca017eb1d4d7a30
>
> As you can see, when I bind the variable magicValue with def (DSL_OK), I can access its
value in my DSL, whereas otherwise (DSL_NOT_OK) I get a
>
> java.lang.NullPointerException: Cannot get property 'magicValue' on null object

in the first case you are accessing a local variable, which is done 
without bothering with owner and delegate of the Closure instance. In 
the second case you are going through these to find the meaning of the 
magicValue. But since you use rehydrate to set owner and delegate to 
null, you will end up in an error.  Why do you do rehydrate at all? 
Maybe in your bigger code there is a need for this I won't see here, but 
in what I see I obviously fail to see the need. If you have to use it, 
then of course you will have to set owner and/or delegate, or else you 
won't be able to sue the standard mechanisms to access the binding from 
the Closure instance

bye Jochen

Mime
View raw message