简体   繁体   English

Jenkins Groovy访问属性时出现StackOverFlowError

[英]Jenkins Groovy StackOverFlowError when accessing a property

I'm trying to write a small job DSL, but I'm struggling with getting java.lang.StackOverflowError errors when accessing a class property. 我正在尝试编写小型作业DSL,但在访问类属性时遇到java.lang.StackOverflowError错误的问题。

Therefore not even a complex script is necessary. 因此,甚至不需要复杂的脚本。 See the following script 请参阅以下脚本

class Komponente {

  String name

  Komponente(name) {
    this.name = name
  }

  String getName() {
    return this.name
  }  

  String toString() {
    return 'Klasse: Komponente (name: [' + this.name +'])'
  }
}

Komponente komponente = new Komponente('Testkomponente')

println 'Erstellte Komponente: ' + komponente.getName()

When running it on the Groovy web console it works fine, but when running it in my Jenkins I get: Groovy Web控制台上运行它时,它可以正常工作,但是在我的Jenkins中运行它时,我得到:

FATAL: null
java.lang.StackOverflowError
  at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:1038)
  at java.lang.ClassLoader.loadClass(ClassLoader.java:406)
  at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:677)
  at groovy.lang.GroovyClassLoader$InnerLoader.loadClass(GroovyClassLoader.java:425)
  at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:787)
  at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:775)
  at sun.reflect.GeneratedMethodAccessor316.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
  at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
  at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1850)
  at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3758)
  at Komponente.getProperty(script)
  at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:174)
  at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:456)
  at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:290)
  at org.kohsuke.groovy.sandbox.GroovyInterceptor.onGetProperty(GroovyInterceptor.java:68)
  at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:257)
  at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:288)
  at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:292)
  at org.kohsuke.groovy.sandbox.impl.Checker$checkedGetProperty$2.callStatic(Unknown Source)
  at Komponente.getName(script:10)
  at sun.reflect.GeneratedMethodAccessor316.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
  at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
  at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:1850)
  at groovy.lang.MetaClassImpl.getProperty(MetaClassImpl.java:3758)
  at Komponente.getProperty(script)
  at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:174)
  at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:456)
  at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:290)
  at org.kohsuke.groovy.sandbox.GroovyInterceptor.onGetProperty(GroovyInterceptor.java:68)
  at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:257)
  at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:288)
  at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:292)
  at org.kohsuke.groovy.sandbox.impl.Checker$checkedGetProperty$2.callStatic(Unknown Source)
  at Komponente.getName(script:10)
  ...

  (As you can see this repeates)

How can I access a class property in a Groovy script running on Jenkins, without getting StackOverflowError exception? 如何在Jenkins上运行的Groovy脚本中访问类属性,而不会出现StackOverflowError异常?

My system: 我的系统:

  • Jenkins-version is 2.73.3 Jenkins版本是2.73.3
  • JobDSL Plugin 1.68 JobDSL插件1.68
  • Stapler Groovy module org.kohsuke.stapler:stapler-groovy:1.250 订书机Groovy模块org.kohsuke.stapler:stapler-groovy:1.250
  • Apache Groovy org.codehaus.groovy:groovy-all:2.4.11 Apache Groovy org.codehaus.groovy:groovy-all:2.4.11

I already did some searching for this error message, but all Jenkins-Issues I found were fixed and closed at least in 2.7.1 so should be included in my jenkins version. 我已经在搜索此错误消息,但是我发现的所有Jenkins问题均已修复,并且至少在2.7.1中已关闭,因此应包含在我的jenkins版本中。

Remove getName() method from your class. 从您的类中删除getName()方法。 When you specify class field like String name you get methods String getName() and void setName(String name) out of the box. 当您指定类字段(例如String name您可以立即使用String getName()void setName(String name)

Keep in mind that Jenkins Groovy script execution environment is a little bit different than the plain Groovy (eg in Groovy console) - Jenkins uses groovy-cps execution environment. 请记住,Jenkins Groovy脚本执行环境与普通Groovy有所不同(例如在Groovy控制台中)-Jenkins使用groovy-cps执行环境。

In your case following class org.kohsuke.groovy.sandbox.impl.Checker caused errors - according to your stack trace calling Komponente.getName() triggered Komponente.getProperty() method through the following execution chain: 在您的情况下,以下类org.kohsuke.groovy.sandbox.impl.Checker导致错误-根据您的堆栈跟踪,调用Komponente.getName()通过以下执行链触发了Komponente.getProperty()方法:

  at Komponente.getProperty(script)
  at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:174)
  at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:456)
  at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:290)
  at org.kohsuke.groovy.sandbox.GroovyInterceptor.onGetProperty(GroovyInterceptor.java:68)
  at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:257)
  at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:288)
  at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:292)
  at org.kohsuke.groovy.sandbox.impl.Checker$checkedGetProperty$2.callStatic(Unknown Source)
  at Komponente.getName(script:10)

And Komponente.getProperty() triggered Komponente.getName() and you run into infinite loop that caused StackOverflowError . 然后Komponente.getProperty()触发了Komponente.getName() ,您遇到了导致StackOverflowError无限循环。

Similar problem happened when I copied your class to my test pipeline script, here is the stack trace I got: 当我将类复制到测试管道脚本时,发生了类似的问题,这是我得到的堆栈跟踪:

Started by user admin
[Pipeline] End of Pipeline
java.lang.StackOverflowError: Excessively nested closures/functions at Komponente.getName(WorkflowScript:10) - look for unbounded recursion - call depth: 1025
    at com.cloudbees.groovy.cps.impl.CpsFunction.invoke(CpsFunction.java:28)
    at com.cloudbees.groovy.cps.impl.CpsCallableInvocation.invoke(CpsCallableInvocation.java:40)
    at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:62)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:109)
    at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixName(FunctionCallBlock.java:77)
    at sun.reflect.GeneratedMethodAccessor106.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
    at com.cloudbees.groovy.cps.impl.ConstantBlock.eval(ConstantBlock.java:21)
    at com.cloudbees.groovy.cps.Next.step(Next.java:83)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:174)
    at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:163)
    at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:122)
    at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:261)
    at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:163)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:19)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:35)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable$1.call(SandboxContinuable.java:32)
    at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
    at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:32)
    at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:331)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:82)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:243)
    at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:231)
    at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:64)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:112)
    at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Finished: FAILURE

It's not that straightforward as yours, but it is caused by the same thing. 它不像您那样简单明了,而是由同一件事引起的。 When I removed String getName() method it worked as expected. 当我删除String getName()方法时,它按预期工作。 It should work for you as well. 它也应该为您工作。 Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM