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

Unable to call super methods inside closure defined in class method

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • Jenkins: 2.121.1
      Script Security Plugin: 1.44
      workflow-cps-plugin: 2.53

      CPS / Script security mechanism fails to look up methods in super class if prefixed with the super keyword. Instead the error org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: No such method found: super.method org.jenkinsci.plugins.workflow.cps.CpsClosure2 ... is thrown.

      The following pipeline code reproduces the problem:

      abstract class A implements Serializable {
          String f() {
              return "In A#f()\n"
          }
      }
      
      class B extends A {
          @Override
          String f() {
              def c = {
                  def s = super.f()
                  s += "In B#f()\n"
                  return s
              }
              return c()
          }
      }
      
      def b = new B()
      echo b.f()
      

      The expected output is:

      [Pipeline] echo
      In A#f()
      In B#f()
      

      but instead the following exception is thrown:

      No such method found: super.method org.jenkinsci.plugins.workflow.cps.CpsClosure2 f. Administrators can decide whether to approve or reject this signature.
      With CPS:
      org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: No such method found: super.method org.jenkinsci.plugins.workflow.cps.CpsClosure2 f
      	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onSuperCall(SandboxInterceptor.java:398)
      	at org.kohsuke.groovy.sandbox.impl.Checker$4.call(Checker.java:211)
      	at org.kohsuke.groovy.sandbox.impl.Checker.checkedSuperCall(Checker.java:221)
      	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.superCall(SandboxInvoker.java:25)
      	at B.f(WorkflowScript:16)
      	at B.f(WorkflowScript:20)
      	at WorkflowScript.run(WorkflowScript:50)
      	at ___cps.transform___(Native Method)
      	at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:54)
      	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.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	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$101(SandboxContinuable.java:34)
      	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.lambda$run0$0(SandboxContinuable.java:59)
      	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovySandbox.runInSandbox(GroovySandbox.java:108)
      	at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:58)
      	at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:174)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:332)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.access$200(CpsThreadGroup.java:83)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:244)
      	at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:232)
      	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:131)
      	at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
      	at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:59)
      	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:1149)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      	at java.lang.Thread.run(Thread.java:748)
      

      Adding @NonCPS makes the code execute as expected, the downside is that it isn't possible to use pipeline steps:

      abstract class NonCPS_A implements Serializable {
          @NonCPS
          String f() {
              return "In NonCPS_A#f()\n"
          }
      }
      
      class NonCPS_B extends NonCPS_A {
          @Override
          @NonCPS
          String f() {
              def c = {
                  def s = super.f()
                  s += "In NonCPS_B#f()\n"
                  return s
              }
              return c()
          }
      }
      
      def nonCPS_b = new NonCPS_B()
      echo nonCPS_b.f()
      

            Unassigned Unassigned
            jons Jon Sten
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: