Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-46145

Groovy Traits are not supported

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • workflow-cps-plugin
    • None

      Hi.

      The following usage example of using traits in pipelines does not work:

      • src/Theon.groovy :
        class Theon implements TraitOr {
            def bar() { 42 }
        }
      • src/TraitOr.groovy :
        trait TraitOr {
            def foo() { bar() }
        }
        
      • vars/test.groovy
        import Theon
        def foobar () {
            new Theon().bar()
        }
        //foobar() // uncomment to test invocation with standard Groovy interpreter
        

      I get the following stracktrace (with Jenkins plugins: "Pipeline"==2.5, "Pipeline: Groovy"==2.39 and "Pipeline: Shared Groovy Libraries"=2.8), whereas it works fine in Groovy standard interpreter 2.4.8 with Java8:

      hudson.remoting.ProxyException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      General error during canonicalization: []
      
      java.lang.UnsupportedOperationException: []
      	at com.cloudbees.groovy.cps.CpsTransformer.visitArrayExpression(CpsTransformer.java:1124)
      	at org.codehaus.groovy.ast.expr.ArrayExpression.visit(ArrayExpression.java:88)
      	at com.cloudbees.groovy.cps.CpsTransformer.visit(CpsTransformer.java:335)
      	at com.cloudbees.groovy.cps.CpsTransformer.visit(CpsTransformer.java:341)
      	at com.cloudbees.groovy.cps.CpsTransformer$18.run(CpsTransformer.java:678)
      	at com.cloudbees.groovy.cps.CpsTransformer.makeChildren(CpsTransformer.java:424)
      	at com.cloudbees.groovy.cps.CpsTransformer.makeNode(CpsTransformer.java:387)
      	at com.cloudbees.groovy.cps.CpsTransformer.visitStaticMethodCallExpression(CpsTransformer.java:672)
      	at org.codehaus.groovy.ast.expr.StaticMethodCallExpression.visit(StaticMethodCallExpression.java:46)
      	at com.cloudbees.groovy.cps.CpsTransformer.visit(CpsTransformer.java:335)
      	at com.cloudbees.groovy.cps.CpsTransformer$47.run(CpsTransformer.java:1188)
      	at com.cloudbees.groovy.cps.CpsTransformer.makeChildren(CpsTransformer.java:424)
      	at com.cloudbees.groovy.cps.CpsTransformer.makeNode(CpsTransformer.java:387)
      	at com.cloudbees.groovy.cps.CpsTransformer.visitCastExpression(CpsTransformer.java:1184)
      	at org.codehaus.groovy.ast.expr.CastExpression.visit(CastExpression.java:87)
      	at com.cloudbees.groovy.cps.CpsTransformer.visit(CpsTransformer.java:335)
      	at com.cloudbees.groovy.cps.CpsTransformer.visitExpressionStatement(CpsTransformer.java:566)
      	at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:42)
      	at com.cloudbees.groovy.cps.CpsTransformer.visit(CpsTransformer.java:335)
      	at com.cloudbees.groovy.cps.CpsTransformer$10.run(CpsTransformer.java:558)
      	at com.cloudbees.groovy.cps.CpsTransformer.makeChildren(CpsTransformer.java:424)
      	at com.cloudbees.groovy.cps.CpsTransformer.makeNode(CpsTransformer.java:387)
      	at com.cloudbees.groovy.cps.CpsTransformer.visitIfElse(CpsTransformer.java:554)
      	at org.codehaus.groovy.ast.stmt.IfStatement.visit(IfStatement.java:43)
      	at com.cloudbees.groovy.cps.CpsTransformer.visit(CpsTransformer.java:335)
      	at com.cloudbees.groovy.cps.CpsTransformer$2.run(CpsTransformer.java:366)
      	at com.cloudbees.groovy.cps.CpsTransformer.makeChildren(CpsTransformer.java:424)
      	at com.cloudbees.groovy.cps.CpsTransformer.makeNode(CpsTransformer.java:387)
      	at com.cloudbees.groovy.cps.CpsTransformer.visitWithSafepoint(CpsTransformer.java:352)
      	at com.cloudbees.groovy.cps.CpsTransformer.visitMethod(CpsTransformer.java:212)
      	at com.cloudbees.groovy.cps.CpsTransformer.call(CpsTransformer.java:126)
      	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1065)
      	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
      	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
      	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
      	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
      	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
      	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:254)
      	at groovy.lang.GroovyClassLoader.recompile(GroovyClassLoader.java:761)
      	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:718)
      	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:787)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
      	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell$TimingLoader.loadClass(CpsGroovyShell.java:156)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
      	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:677)
      	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:787)
      	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:775)
      	at org.jenkinsci.plugins.workflow.cps.global.UserDefinedGlobalVariable.getValue(UserDefinedGlobalVariable.java:54)
      	at org.jenkinsci.plugins.workflow.cps.CpsScript.getProperty(CpsScript.java:121)
      	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:284)
      	at org.kohsuke.groovy.sandbox.GroovyInterceptor.onGetProperty(GroovyInterceptor.java:68)
      	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:316)
      	at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:282)
      	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:286)
      	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:262)
      	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:262)
      	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:262)
      	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:29)
      	at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
      	at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:74)
      	at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
      	at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.fixName(PropertyishBlock.java:66)
      	at sun.reflect.GeneratedMethodAccessor178.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:173)
      	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:162)
      	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:162)
      	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:330)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:82)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:242)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:230)
      	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)
      
      1 error
      
      	at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
      	at org.codehaus.groovy.control.CompilationUnit.applyToPrimaryClassNodes(CompilationUnit.java:1085)
      	at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:603)
      	at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
      	at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
      	at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
      	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
      	at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:254)
      	at groovy.lang.GroovyClassLoader.recompile(GroovyClassLoader.java:761)
      	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:718)
      	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:787)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
      	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell$TimingLoader.loadClass(CpsGroovyShell.java:156)
      	at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
      	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:677)
      	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:787)
      	at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:775)
      	at org.jenkinsci.plugins.workflow.cps.global.UserDefinedGlobalVariable.getValue(UserDefinedGlobalVariable.java:54)
      	at org.jenkinsci.plugins.workflow.cps.CpsScript.getProperty(CpsScript.java:121)
      	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:284)
      	at org.kohsuke.groovy.sandbox.GroovyInterceptor.onGetProperty(GroovyInterceptor.java:68)
      	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onGetProperty(SandboxInterceptor.java:316)
      	at org.kohsuke.groovy.sandbox.impl.Checker$6.call(Checker.java:282)
      	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:286)
      	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:262)
      	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:262)
      	at org.kohsuke.groovy.sandbox.impl.Checker.checkedGetProperty(Checker.java:262)
      	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.getProperty(SandboxInvoker.java:29)
      	at com.cloudbees.groovy.cps.impl.PropertyAccessBlock.rawGet(PropertyAccessBlock.java:20)
      	at WorkflowScript.run(WorkflowScript:11)
      	at ___cps.transform___(Native Method)
      	at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.get(PropertyishBlock.java:74)
      	at com.cloudbees.groovy.cps.LValueBlock$GetAdapter.receive(LValueBlock.java:30)
      	at com.cloudbees.groovy.cps.impl.PropertyishBlock$ContinuationImpl.fixName(PropertyishBlock.java:66)
      	at sun.reflect.GeneratedMethodAccessor178.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:173)
      	at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:162)
      	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:162)
      	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:330)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$100(CpsThreadGroup.java:82)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:242)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:230)
      	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
      

      With only basic knowledge of the "groovy-cps" implementation, I naively tried to write a minimal test case in Groovy, but the following code (inspired by AbstractGroovyCpsTest.groovy) fails to reproduce the issue I see in Jenkins :

      @Grab(group='com.cloudbees', module='groovy-cps', version='1.18')
      
      import org.codehaus.groovy.control.CompilerConfiguration
      import com.cloudbees.groovy.cps.*
      import com.cloudbees.groovy.cps.impl.*
      
      def cc = new CompilerConfiguration()
      cc.addCompilationCustomizers(new CpsTransformer())
      cc.scriptBaseClass = SerializableScript.class.name
      
      String code = """
      import Theon
      def foobar () {
          new Theon().bar()
      }
      foobar()
      """
      Script script = new GroovyShell(new GroovyClassLoader(this.class.classLoader), binding, cc).parse(code)
      try {
          script.run()
      } catch (CpsCallableInvocation inv) {
          println(inv.invoke(null, null, Continuation.HALT).run(10000).replay())
      }
      

      (I think this code fails to use a CPS-transformed version of the Theon & TraitOr classes)

      What do you think: is this a "groovy-cps" issue or a "workflow-cps-plugin" issue ?

            Unassigned Unassigned
            lucasc Lucas Cimon
            Votes:
            20 Vote for this issue
            Watchers:
            23 Start watching this issue

              Created:
              Updated: