• Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • workflow-cps-plugin
    • Jenkins 1.6.11
      Workflow 1.6

      The method pointer operator (.&) is entirely broken. The following test:

      def bar = 'foo'.&toUpperCase
      

      Results in:

      startup failed:
      General error during canonicalization: java.lang.UnsupportedOperationException
      

      Plus a giant call stack.

      The workaround is to instead explicitly create a closure which calls the method, which is syntactically cumbersome and reduces semantic readability.

          [JENKINS-28321] Method pointer operator (.&) broken

          Jesse Glick added a comment -

          Just one of many exotic Groovy language features not currently supported by the CPS engine.

          Jesse Glick added a comment - Just one of many exotic Groovy language features not currently supported by the CPS engine.

          Following works by the way:

          def build() {
              def methodRef = this.&prepareConfig()
              methodRef // prepareConfig() method will be called here
          }
          
          def prepareConfig() {
          }
          
          def build() {
              def ref = methodRef()
              ref // prepareConfig() method will be called here
          }
          
          def methodRef() {
              return this.&prepareConfig()
          }
          
          def prepareConfig() {
          }
          

          So it's not entirely broken.

          Veaceslav Gaidarji added a comment - Following works by the way: def build() { def methodRef = this .&prepareConfig() methodRef // prepareConfig() method will be called here } def prepareConfig() { } def build() { def ref = methodRef() ref // prepareConfig() method will be called here } def methodRef() { return this .&prepareConfig() } def prepareConfig() { } So it's not entirely broken.

          Andrew Bayer added a comment -

          This works in workflow-cps 2.39 and has testing - specifically covering that you can't escape the sandbox through utilization of method pointers, but just getting that far and the specific error message verifies that this works otherwise.

          Andrew Bayer added a comment - This works in workflow-cps 2.39 and has testing - specifically covering that you can't escape the sandbox through utilization of method pointers, but just getting that far and the specific error message verifies that this works otherwise.

          Jesse Glick added a comment -

          You need test coverage demonstrating that the calls works as intended if it is whitelisted.

          Jesse Glick added a comment - You need test coverage demonstrating that the calls works as intended if it is whitelisted.

          Andrew Bayer added a comment -

          Fair enough. On it.

          Andrew Bayer added a comment - Fair enough. On it.

          Code changed in jenkins
          User: Andrew Bayer
          Path:
          src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinition2Test.java
          http://jenkins-ci.org/commit/workflow-cps-plugin/ee83ee52d5d14e30cc2c3092ae5463add860ab73
          Log:
          JENKINS-28321 Verify that whitelisted method pointers can be used.

          SCM/JIRA link daemon added a comment - Code changed in jenkins User: Andrew Bayer Path: src/test/java/org/jenkinsci/plugins/workflow/cps/CpsFlowDefinition2Test.java http://jenkins-ci.org/commit/workflow-cps-plugin/ee83ee52d5d14e30cc2c3092ae5463add860ab73 Log: JENKINS-28321 Verify that whitelisted method pointers can be used.

            jglick Jesse Glick
            sumdumgai A C
            Votes:
            3 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved: