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

Metaprogramming with InvokerHelper and MethodMissing triggers CPS MisMatch log

    Details

    • Similar Issues:
    • Released As:
      workflow-cps 2.73

      Description

      I currently work on a plugin ([Templating Engine Plugin|https://plugins.jenkins.io/templating-engine]) that relies on being able to leverage metaprogramming techniques such as using snippets like:

      InvokerHelper.getMetaClass(impl).invokeMethod(impl, methodName, args)
      

      or methodMissing to control program flow. 

       

      The introduction of logging CPS mismatched method names has resulted in continuously logging these occurrences. 

       

      Is there a way to work around the CPS mismatch logs for instances such as leveraging methodMissing or the InvokerHelper to dynamically execute methods? 

       

      methodMissing log:

      expected to call org.boozallen.plugins.jte.binding.injectors.StepWrapper.doThing but wound up catching org.boozallen.plugins.jte.binding.injectors.StepWrapper.methodMissing; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/
      expected to call org.boozallen.plugins.jte.hooks.Hooks.invoke but wound up catching script15632181891161818312862.call; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/

      InvokerHelper log:

      expected to call groovy.lang.ExpandoMetaClass.invokeMethod but wound up catching script1563218188258613791966.doThing; see: https://jenkins.io/redirect/pipeline-cps-method-mismatches/
      

       

      Simplest example to reproduce: 

       

      import org.codehaus.groovy.runtime.InvokerHelper
      c = {
          println "doing a thing"
      }
      InvokerHelper.getMetaClass(c).invokeMethod(c, "call", null)
      

       

        Attachments

          Issue Links

            Activity

            Hide
            sterrana Steven Terrana added a comment - - edited

            I have implemented an approach to solving this problem and opened a pull request: 

            https://github.com/jenkinsci/workflow-cps-plugin/pull/305

             

            cc: Jesse Glick Andrew Bayer

            Show
            sterrana Steven Terrana added a comment - - edited I have implemented an approach to solving this problem and opened a pull request:  https://github.com/jenkinsci/workflow-cps-plugin/pull/305   cc: Jesse Glick Andrew Bayer
            Hide
            jglick Jesse Glick added a comment -

            With workflow-cps #306, probably falls on me or Devin Nusbaum to play with a groovy-cps patch that would resolve the issue.

            One thing I should have done initially, but neglected to, was write unit tests in groovy-cps for this. Quicker to iterate than the full functional tests in workflow-cps, though we need at least some of those as well, since “things happen” when a library is being used in a complex context.

            Show
            jglick Jesse Glick added a comment - With workflow-cps #306, probably falls on me or Devin Nusbaum to play with a groovy-cps patch that would resolve the issue. One thing I should have done initially, but neglected to, was write unit tests in groovy-cps for this. Quicker to iterate than the full functional tests in workflow-cps , though we need at least some of those as well, since “things happen” when a library is being used in a complex context.
            Hide
            sterrana Steven Terrana added a comment -

            Hey @jglick, i attempted a patch at this in groovy-cps and opened a PR.

            https://github.com/cloudbees/groovy-cps/pull/99

            Show
            sterrana Steven Terrana added a comment - Hey @jglick, i attempted a patch at this in groovy-cps and opened a PR. https://github.com/cloudbees/groovy-cps/pull/99
            Hide
            dnusbaum Devin Nusbaum added a comment -

            A fix for this issue was just released in version 2.73 of Pipeline: Groovy Plugin.

            Show
            dnusbaum Devin Nusbaum added a comment - A fix for this issue was just released in version 2.73 of Pipeline: Groovy Plugin.

              People

              • Assignee:
                sterrana Steven Terrana
                Reporter:
                sterrana Steven Terrana
              • Votes:
                1 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: