• 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 ?

          [JENKINS-46145] Groovy Traits are not supported

          We're also affected by this issue. Because the error message was so weird, I've actually spent a lot of time figuring out why my pipeline shared library works fine under plain groovy, but not inside Jenkins.

          Is there any way to disable cps for my shared library or some other trick to make it work while keep using traits?

          A simple Jenkinsfile that can be used to reproduce the issue:

          trait A {
            def sayHello(script) {
              script.echo "Hello"
            }
          }
          class B implements A {}
          new B().sayHello(this)

          which results in:

          org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
          General error during canonicalization: [script]
          
          java.lang.UnsupportedOperationException: [script]
          	at com.cloudbees.groovy.cps.CpsTransformer.visitArrayExpression(CpsTransformer.java:1179)
          	at org.codehaus.groovy.ast.expr.ArrayExpression.visit(ArrayExpression.java:88)
          	at com.cloudbees.groovy.cps.CpsTransformer.visit(CpsTransformer.java:341)
          	at com.cloudbees.groovy.cps.CpsTransformer.visit(CpsTransformer.java:347)
          	at com.cloudbees.groovy.cps.CpsTransformer$18.run(CpsTransformer.java:684)
          	at com.cloudbees.groovy.cps.CpsTransformer.makeChildren(CpsTransformer.java:430)
          	at com.cloudbees.groovy.cps.CpsTransformer.makeNode(CpsTransformer.java:393)
          	at com.cloudbees.groovy.cps.CpsTransformer.visitStaticMethodCallExpression(CpsTransformer.java:678)
          	at org.codehaus.groovy.ast.expr.StaticMethodCallExpression.visit(StaticMethodCallExpression.java:46)
          	at com.cloudbees.groovy.cps.CpsTransformer.visit(CpsTransformer.java:341)
          	at com.cloudbees.groovy.cps.CpsTransformer$48.run(CpsTransformer.java:1243)
          	at com.cloudbees.groovy.cps.CpsTransformer.makeChildren(CpsTransformer.java:430)
          	at com.cloudbees.groovy.cps.CpsTransformer.makeNode(CpsTransformer.java:393)
          	at com.cloudbees.groovy.cps.CpsTransformer.visitCastExpression(CpsTransformer.java:1239)
          	at com.cloudbees.groovy.cps.SandboxCpsTransformer.visitCastExpression(SandboxCpsTransformer.java:80)
          	at org.codehaus.groovy.ast.expr.CastExpression.visit(CastExpression.java:87)
          	at com.cloudbees.groovy.cps.CpsTransformer.visit(CpsTransformer.java:341)
          	at com.cloudbees.groovy.cps.CpsTransformer.visitExpressionStatement(CpsTransformer.java:572)
          	at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:42)
          	at com.cloudbees.groovy.cps.CpsTransformer.visit(CpsTransformer.java:341)
          	at com.cloudbees.groovy.cps.CpsTransformer$10.run(CpsTransformer.java:564)
          	at com.cloudbees.groovy.cps.CpsTransformer.makeChildren(CpsTransformer.java:430)
          	at com.cloudbees.groovy.cps.CpsTransformer.makeNode(CpsTransformer.java:393)
          	at com.cloudbees.groovy.cps.CpsTransformer.visitIfElse(CpsTransformer.java:560)
          	at org.codehaus.groovy.ast.stmt.IfStatement.visit(IfStatement.java:43)
          	at com.cloudbees.groovy.cps.CpsTransformer.visit(CpsTransformer.java:341)
          	at com.cloudbees.groovy.cps.CpsTransformer$2.run(CpsTransformer.java:372)
          	at com.cloudbees.groovy.cps.CpsTransformer.makeChildren(CpsTransformer.java:430)
          	at com.cloudbees.groovy.cps.CpsTransformer.makeNode(CpsTransformer.java:393)
          	at com.cloudbees.groovy.cps.CpsTransformer.visitWithSafepoint(CpsTransformer.java:358)
          	at com.cloudbees.groovy.cps.CpsTransformer.visitMethod(CpsTransformer.java:217)
          	at com.cloudbees.groovy.cps.CpsTransformer.call(CpsTransformer.java:132)
          	at com.cloudbees.groovy.cps.SandboxCpsTransformer.call(SandboxCpsTransformer.java:29)
          	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.GroovyShell.parseClass(GroovyShell.java:688)
          	at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
          	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:133)
          	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
          	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:557)
          	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:518)
          	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:290)
          	at hudson.model.ResourceController.execute(ResourceController.java:97)
          	at hudson.model.Executor.run(Executor.java:429)
          
          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.GroovyShell.parseClass(GroovyShell.java:688)
          	at groovy.lang.GroovyShell.parse(GroovyShell.java:700)
          	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:133)
          	at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127)
          	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:557)
          	at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:518)
          	at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:290)
          	at hudson.model.ResourceController.execute(ResourceController.java:97)
          	at hudson.model.Executor.run(Executor.java:429)
          Finished: FAILURE
          

          Piotr Paczyński added a comment - We're also affected by this issue. Because the error message was so weird, I've actually spent a lot of time figuring out why my pipeline shared library works fine under plain groovy, but not inside Jenkins. Is there any way to disable cps for my shared library or some other trick to make it work while keep using traits? A simple Jenkinsfile that can be used to reproduce the issue: trait A { def sayHello(script) { script.echo "Hello" } } class B implements A {} new B().sayHello(this) which results in: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: General error during canonicalization: [script] java.lang.UnsupportedOperationException: [script] at com.cloudbees.groovy.cps.CpsTransformer.visitArrayExpression(CpsTransformer.java:1179) at org.codehaus.groovy.ast.expr.ArrayExpression.visit(ArrayExpression.java:88) at com.cloudbees.groovy.cps.CpsTransformer.visit(CpsTransformer.java:341) at com.cloudbees.groovy.cps.CpsTransformer.visit(CpsTransformer.java:347) at com.cloudbees.groovy.cps.CpsTransformer$18.run(CpsTransformer.java:684) at com.cloudbees.groovy.cps.CpsTransformer.makeChildren(CpsTransformer.java:430) at com.cloudbees.groovy.cps.CpsTransformer.makeNode(CpsTransformer.java:393) at com.cloudbees.groovy.cps.CpsTransformer.visitStaticMethodCallExpression(CpsTransformer.java:678) at org.codehaus.groovy.ast.expr.StaticMethodCallExpression.visit(StaticMethodCallExpression.java:46) at com.cloudbees.groovy.cps.CpsTransformer.visit(CpsTransformer.java:341) at com.cloudbees.groovy.cps.CpsTransformer$48.run(CpsTransformer.java:1243) at com.cloudbees.groovy.cps.CpsTransformer.makeChildren(CpsTransformer.java:430) at com.cloudbees.groovy.cps.CpsTransformer.makeNode(CpsTransformer.java:393) at com.cloudbees.groovy.cps.CpsTransformer.visitCastExpression(CpsTransformer.java:1239) at com.cloudbees.groovy.cps.SandboxCpsTransformer.visitCastExpression(SandboxCpsTransformer.java:80) at org.codehaus.groovy.ast.expr.CastExpression.visit(CastExpression.java:87) at com.cloudbees.groovy.cps.CpsTransformer.visit(CpsTransformer.java:341) at com.cloudbees.groovy.cps.CpsTransformer.visitExpressionStatement(CpsTransformer.java:572) at org.codehaus.groovy.ast.stmt.ExpressionStatement.visit(ExpressionStatement.java:42) at com.cloudbees.groovy.cps.CpsTransformer.visit(CpsTransformer.java:341) at com.cloudbees.groovy.cps.CpsTransformer$10.run(CpsTransformer.java:564) at com.cloudbees.groovy.cps.CpsTransformer.makeChildren(CpsTransformer.java:430) at com.cloudbees.groovy.cps.CpsTransformer.makeNode(CpsTransformer.java:393) at com.cloudbees.groovy.cps.CpsTransformer.visitIfElse(CpsTransformer.java:560) at org.codehaus.groovy.ast.stmt.IfStatement.visit(IfStatement.java:43) at com.cloudbees.groovy.cps.CpsTransformer.visit(CpsTransformer.java:341) at com.cloudbees.groovy.cps.CpsTransformer$2.run(CpsTransformer.java:372) at com.cloudbees.groovy.cps.CpsTransformer.makeChildren(CpsTransformer.java:430) at com.cloudbees.groovy.cps.CpsTransformer.makeNode(CpsTransformer.java:393) at com.cloudbees.groovy.cps.CpsTransformer.visitWithSafepoint(CpsTransformer.java:358) at com.cloudbees.groovy.cps.CpsTransformer.visitMethod(CpsTransformer.java:217) at com.cloudbees.groovy.cps.CpsTransformer.call(CpsTransformer.java:132) at com.cloudbees.groovy.cps.SandboxCpsTransformer.call(SandboxCpsTransformer.java:29) 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.GroovyShell.parseClass(GroovyShell.java:688) at groovy.lang.GroovyShell.parse(GroovyShell.java:700) at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:133) at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127) at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:557) at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:518) at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:290) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:429) 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.GroovyShell.parseClass(GroovyShell.java:688) at groovy.lang.GroovyShell.parse(GroovyShell.java:700) at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.doParse(CpsGroovyShell.java:133) at org.jenkinsci.plugins.workflow.cps.CpsGroovyShell.reparse(CpsGroovyShell.java:127) at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.parseScript(CpsFlowExecution.java:557) at org.jenkinsci.plugins.workflow.cps.CpsFlowExecution.start(CpsFlowExecution.java:518) at org.jenkinsci.plugins.workflow.job.WorkflowRun.run(WorkflowRun.java:290) at hudson.model.ResourceController.execute(ResourceController.java:97) at hudson.model.Executor.run(Executor.java:429) Finished: FAILURE

          Dee Kryvenko added a comment -

          All of the sudden, I just ran into that issue. This CPS thing definitely gives a lot of benefits, but there should be a way to choose that I want to use library X with CPS but library Y is just plain Groovy. Would not be a problem, but here and there I ran into things that works in plain Groovy but do not in CPS - ending up blocked while have no benefit being CPS-ed in this particular piece of code.

          Dee Kryvenko added a comment - All of the sudden, I just ran into that issue. This CPS thing definitely gives a lot of benefits, but there should be a way to choose that I want to use library X with CPS but library Y is just plain Groovy. Would not be a problem, but here and there I ran into things that works in plain Groovy but do not in CPS - ending up blocked while have no benefit being CPS-ed in this particular piece of code.

          Dee Kryvenko added a comment -

          For whoever else run into that issue: good old @Mixin seems to be working fine. It is deprecated in favor to traits, though, so dunno how long is it going to be available in the upcoming groovy versions.

          http://docs.groovy-lang.org/latest/html/api/groovy/lang/Mixin.html

          Dee Kryvenko added a comment - For whoever else run into that issue: good old @Mixin seems to be working fine. It is deprecated in favor to traits, though, so dunno how long is it going to be available in the upcoming groovy versions. http://docs.groovy-lang.org/latest/html/api/groovy/lang/Mixin.html

          Bernardo Vale added a comment -

          Thanks for the tip llibicpep , works fine using Mixin annotation. 

          Bernardo Vale added a comment - Thanks for the tip llibicpep , works fine using Mixin annotation. 

          Eugene G added a comment -

          Any chance to get the feature? Mixins demonstrate weird behavior in some corner cases.

          Eugene G added a comment - Any chance to get the feature? Mixins demonstrate weird behavior in some corner cases.

          Dee Kryvenko added a comment -

          3 years in and no update, these artificial limitations driving me nuts. FYI to the subscribers of this issue - there is another related issue where jglick said these types of issues will not be worked on as CPS engine is nothing but a waste of time (with that last part I couldn't agree more). I wrote a comment there https://issues.jenkins.io/browse/JENKINS-45901?focusedCommentId=409834&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-409834 with some reasoning why this is important and have to be dealt with one way or the other. Preferably - allowing us to disable CPS especially in the case it is officially considered a waste of time. With some community support maybe we'll be able to drag some attention to our cause here...

          Dee Kryvenko added a comment - 3 years in and no update, these artificial limitations driving me nuts. FYI to the subscribers of this issue - there is another related issue where jglick  said these types of issues will not be worked on as CPS engine is nothing but a waste of time (with that last part I couldn't agree more). I wrote a comment there https://issues.jenkins.io/browse/JENKINS-45901?focusedCommentId=409834&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-409834  with some reasoning why this is important and have to be dealt with one way or the other. Preferably - allowing us to disable CPS especially in the case it is officially considered a waste of time. With some community support maybe we'll be able to drag some attention to our cause here...

          Andreas Messer added a comment - - edited

          Its really a pain this is not working. Makes things so complicated to workaround. Even not working in NonCPS transformed functions. Produces useless error messages like

          expected to call com.hilscher.spc.dsl.Declarer$ComponentBuildDeclarer.<init> but wound up catching com.hilscher.spc.dsl.ArtifactDeclarer$Trait$Helper.$static$init$;
          
          file:/srv/jenkins-test/jobs/Profinet/jobs/PSPNCORE%20Build/branches/trunk/builds/379/libs/db271022f02a0dbc8b395d8e472f8b038c5b09b542f0932601ec044397b26efd/src/com/hilscher/spc/dsl/Declarer.groovy: -1: Unsupported array expression for CPS transformation in this context @ line -1, column -1.
          

          Andreas Messer added a comment - - edited Its really a pain this is not working. Makes things so complicated to workaround. Even not working in NonCPS transformed functions. Produces useless error messages like expected to call com.hilscher.spc.dsl.Declarer$ComponentBuildDeclarer.<init> but wound up catching com.hilscher.spc.dsl.ArtifactDeclarer$Trait$Helper.$static$init$; file:/srv/jenkins-test/jobs/Profinet/jobs/PSPNCORE%20Build/branches/trunk/builds/379/libs/db271022f02a0dbc8b395d8e472f8b038c5b09b542f0932601ec044397b26efd/src/com/hilscher/spc/dsl/Declarer.groovy: -1: Unsupported array expression for CPS transformation in this context @ line -1, column -1.

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

              Created:
              Updated: