Hi,

      our custom DSL for Groovy contains 2 methods named the same way, but with a different number of arguments:

      myMethod(boolean watch, String...args)

      myMethod(String...args)

       

      While trying to call the method from a pipeline, I got the following exception:

       

      java.lang.IllegalStateException: cannot compare public com.openshift.jenkins.plugins.OpenShiftDSL$Result com.openshift.jenkins.plugins.OpenShiftDSL.exec(java.lang.Object[]) to public com.openshift.jenkins.plugins.OpenShiftDSL$Result com.openshift.jenkins.plugins.OpenShiftDSL.exec(boolean,java.lang.Object[])
       at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovyCallSiteSelector.isMoreSpecific(GroovyCallSiteSelector.java:291)
       at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovyCallSiteSelector.findMatchingMethod(GroovyCallSiteSelector.java:203)
       at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovyCallSiteSelector.method(GroovyCallSiteSelector.java:150)
       at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:90)
       at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:156)
       at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:160)
       at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
       at WorkflowScript.run(WorkflowScript:13)
       at com.openshift.jenkins.plugins.OpenShiftDSL.withProject(jar:file:/var/lib/jenkins/plugins/openshift-client/WEB-INF/lib/openshift-client.jar!/com/openshift/jenkins/plugins/OpenShiftDSL.groovy:395)

       

       

       

      It seems that this is due to an incomplete implementation of the method comparison in GroovyCallSiteSelector class. A TODO is still present in the code at the following line:

      https://github.com/jenkinsci/script-security-plugin/blob/master/src/main/java/org/jenkinsci/plugins/scriptsecurity/sandbox/groovy/GroovyCallSiteSelector.java#L289

       

       

       

       

       

       

          [JENKINS-58611] Implement method comparison for var-args

          Have some common points with:

          https://issues.jenkins-ci.org/browse/JENKINS-56758

           

          Akram Ben Aissi added a comment - Have some common points with: https://issues.jenkins-ci.org/browse/JENKINS-56758  

          Viktor added a comment - - edited

          Bump, also ran into this.

          Added this rule for now:

          ### Global-variables with Varargs break when used in 'parallel'/multiple-executors
          Using varargs (e.g. `def call(Map args=[:], String... inputs)`) within global variables
          (e.g. `./vars/vSh.groovy`) at first looks supported and harmless.
          
          However once multiple Executors call it, as is the case in `parallel()` bodies,
          critical Exceptions like the following can occur easily: ↓
          ```
          [2022-12-10T20:21:48.272Z] hudson.remoting.ProxyException: core.exceptions.AnnotatedException: cannot compare public java.lang.Object vSh.call(java.util.Map,java.lang.Object[]) to public java.lang.Object vSh.call(java.lang.Object[])
          [2022-12-10T20:21:48.272Z] Originates from: class java.lang.IllegalStateException
          ...
          [2022-12-10T20:21:48.272Z] 	at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.callClosureForMapEntry(CpsDefaultGroovyMethods:5361)
          [2022-12-10T20:21:48.272Z] 	at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:2202)
          ...
          [2022-12-10T20:21:48.272Z] 	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovyCallSiteSelector.isMoreSpecific(GroovyCallSiteSelector.java:335)
          [2022-12-10T20:21:48.272Z] 	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovyCallSiteSelector.findMatchingMethod(GroovyCallSiteSelector.java:247)
          [2022-12-10T20:21:48.272Z] 	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovyCallSiteSelector.method(GroovyCallSiteSelector.java:159)
          [2022-12-10T20:21:48.272Z] 	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:95)
          [2022-12-10T20:21:48.272Z] 	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:139)
          [2022-12-10T20:21:48.272Z] 	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:178)
          [2022-12-10T20:21:48.272Z] 	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:182)
          [2022-12-10T20:21:48.272Z] 	at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
          ...
          ```
          

          This TODO looks very much like the issue I was running into: https://github.com/jenkinsci/script-security-plugin/blob/d93135a2fb250c04cc361b0bb1efd809bc63ad08/src/main/java/org/jenkinsci/plugins/scriptsecurity/sandbox/groovy/GroovyCallSiteSelector.java#L333

          Viktor added a comment - - edited Bump, also ran into this. Added this rule for now: ### Global-variables with Varargs break when used in 'parallel'/multiple-executors Using varargs (e.g. `def call(Map args=[:], String... inputs)`) within global variables (e.g. `./vars/vSh.groovy`) at first looks supported and harmless. However once multiple Executors call it, as is the case in `parallel()` bodies, critical Exceptions like the following can occur easily: ↓ ``` [2022-12-10T20:21:48.272Z] hudson.remoting.ProxyException: core.exceptions.AnnotatedException: cannot compare public java.lang.Object vSh.call(java.util.Map,java.lang.Object[]) to public java.lang.Object vSh.call(java.lang.Object[]) [2022-12-10T20:21:48.272Z] Originates from: class java.lang.IllegalStateException ... [2022-12-10T20:21:48.272Z] at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.callClosureForMapEntry(CpsDefaultGroovyMethods:5361) [2022-12-10T20:21:48.272Z] at com.cloudbees.groovy.cps.CpsDefaultGroovyMethods.each(CpsDefaultGroovyMethods:2202) ... [2022-12-10T20:21:48.272Z] at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovyCallSiteSelector.isMoreSpecific(GroovyCallSiteSelector.java:335) [2022-12-10T20:21:48.272Z] at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovyCallSiteSelector.findMatchingMethod(GroovyCallSiteSelector.java:247) [2022-12-10T20:21:48.272Z] at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.GroovyCallSiteSelector.method(GroovyCallSiteSelector.java:159) [2022-12-10T20:21:48.272Z] at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:95) [2022-12-10T20:21:48.272Z] at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:139) [2022-12-10T20:21:48.272Z] at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:178) [2022-12-10T20:21:48.272Z] at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:182) [2022-12-10T20:21:48.272Z] at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17) ... ``` This TODO looks very much like the issue I was running into: https://github.com/jenkinsci/script-security-plugin/blob/d93135a2fb250c04cc361b0bb1efd809bc63ad08/src/main/java/org/jenkinsci/plugins/scriptsecurity/sandbox/groovy/GroovyCallSiteSelector.java#L333

            Unassigned Unassigned
            akram Akram Ben Aissi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: