Well, apparently it is a known issue for about a year, with little activity 
:-(

https://issues.jenkins-ci.org/browse/JENKINS-31484

-M

On Wednesday, September 28, 2016 at 6:00:40 PM UTC-7, Michael Lasevich 
wrote:
>
> Can anyone who understands Groovy/CPS look at this and see if this is even 
> resolvable/fixable?
>
> Ok, so after much hair loss and much unpredictable behavior - I have 
> discovered an ugly bug (feature?) that Groovy getters/setters that work 
> fine under regular Groovy, fail miserably under Pipelines/Jenkins. I 
> suspect this is due to CPS, although I have not yet confirmed that, and 
> wrapping it in @NonCPS tag seems to have not affected the problem....
>
> Consider this simple Groovy demo bean with a custom getter(same thing 
> happens with setters, btw, I just wanted to keep example simple):
>
> class Bean implements Serializable{
>
>  def name = "unset"
>
>
>   String getName(){
>
>    if (this.name == "unset"){
>
>      this.name = "is not set"
>
>    }
>
>    return this.name
>
>  }
>
> }
>
> and following pipeline code is using it:
>
> import Bean
>
> b = new Bean()
>
> echo("Bean name: "+ b.name)
>
>
> The code here works fine under plain Groovy (replace "echo" with 
> "println") - but under pipelines it blows up. Looking under the hood it 
> appears that the 'return this.name' literally throws CPS for a loop, it 
> is being replaced with "return this.getName()" which causes infinite 
> recursion.
>
> Knowing this, the workaround seems to be to change the internal field name 
> to not match the getter/setter pattern - but that causes much ugliness (you 
> are forced to now have both getter/setter for common usage and your 
> getter/setter and your field name do not match)
>
> My suspicion is that this is a bug in CPS, but not clearly understanding 
> the purpose/benefits of CPS - I am unclear if this is even fixable. Best I 
> can figure is that CPS injects a lot of headaches in exchange for ability 
> to serialize your workflow at any point in time - a benefit which I am not 
> sure I care much about, considering bulk of the builds happens in 
> sub-processes outside of CPS control... My point is that I clearly do not 
> understand enough of what is going on or why it is happening under 
> Pipelines but not under Groovy in general.  Can someone who understands 
> this  better see if this is a bug or something inherent to Groovy/CPS setup?
>
> Thanks,
>
> -M
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to jenkinsci-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jenkinsci-users/9aef94fb-ef8f-41bb-81d4-44febb57dfad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to