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

Groovy methods with optional parameter and parameter with method's name failing when optional parameter not specified

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • workflow-cps-plugin
    • None
    • Jenkins: 2.387.2
      OS: Windows Server 2019 - 10.0
      Java: 17.0.4.1 - Eclipse Adoptium (OpenJDK 64-Bit Server VM)
      workflow-cps: 3653.v07ea_433c90b_4

      Groovy methods with:

      • a parameter with the same name as the method
      • an optional parameter
      • called without providing the optional parameter

      apparently aren't being handled correctly anymore. I'm not sure exactly when the behavior changed, but the following example works on:

      • Jenkins 2.346.3 / Pipeline: Groovy 2759.v87459c4eea_ca_  / Java 8

      but fails on:

      • Jenkins 2.387.2 / Pipeline: Groovy Version 3653.v07ea_433c90b_4 / Java 17

      It also works fine in the Jenkins Script Console in both versions.

      Example pipeline script:

      def foo(String foo, Map options = null) {
          println("foo: $foo with: $options");
      }
      
      def bar(String foo, Map options = null) {
          println("bar: $foo with: $options");
      }
      
      bar("test1", [:]);   // Works: no parameters named 'bar'
      bar("test2");        // Works
      
      foo("test3", [:]);   // Works: optional parameter provided
      foo("test4");        // Fails: exception thrown here
      

      This should print:

       

      bar: test1 with: [:]
      bar: test2 with: null
      foo: test3 with: [:]
      foo: test4 with: null

       

      Instead, the final line throws an exception:

      hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: java.lang.String.call() is applicable for argument types: (java.lang.String, null) values: [test4, null]
      Possible solutions: wait(), chars(), any(), trim(), find(), size()
      at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:159)
      at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:178)
      at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:182)
      at com.cloudbees.groovy.cps.sandbox.SandboxInvoker.methodCall(SandboxInvoker.java:17)
      at WorkflowScript.foo(WorkflowScript)
      at WorkflowScript.run(WorkflowScript:13)
      at __cps.transform__(Native Method)
      at com.cloudbees.groovy.cps.impl.ContinuationGroup.methodCall(ContinuationGroup.java:90)
      at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.dispatchOrArg(FunctionCallBlock.java:116)
      at com.cloudbees.groovy.cps.impl.FunctionCallBlock$ContinuationImpl.fixArg(FunctionCallBlock.java:85)
      at jdk.internal.reflect.GeneratedMethodAccessor407.invoke(Unknown Source)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:568)
      at com.cloudbees.groovy.cps.impl.ContinuationPtr$ContinuationImpl.receive(ContinuationPtr.java:72)
      at com.cloudbees.groovy.cps.impl.CastBlock$ContinuationImpl.cast(CastBlock.java:47)
      at jdk.internal.reflect.GeneratedMethodAccessor452.invoke(Unknown Source)
      at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.base/java.lang.reflect.Method.invoke(Method.java:568)
      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:152)
      at com.cloudbees.groovy.cps.Continuable$1.call(Continuable.java:146)
      at org.codehaus.groovy.runtime.GroovyCategorySupport$ThreadCategoryInfo.use(GroovyCategorySupport.java:136)
      at org.codehaus.groovy.runtime.GroovyCategorySupport.use(GroovyCategorySupport.java:275)
      at com.cloudbees.groovy.cps.Continuable.run0(Continuable.java:146)
      at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.access$001(SandboxContinuable.java:18)
      at org.jenkinsci.plugins.workflow.cps.SandboxContinuable.run0(SandboxContinuable.java:51)
      at org.jenkinsci.plugins.workflow.cps.CpsThread.runNextChunk(CpsThread.java:187)
      at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.run(CpsThreadGroup.java:420)
      at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:330)
      at org.jenkinsci.plugins.workflow.cps.CpsThreadGroup$2.call(CpsThreadGroup.java:294)
      at org.jenkinsci.plugins.workflow.cps.CpsVmExecutorService$2.call(CpsVmExecutorService.java:67)
      at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      at hudson.remoting.SingleLaneExecutorService$1.run(SingleLaneExecutorService.java:139)
      at jenkins.util.ContextResettingExecutorService$1.run(ContextResettingExecutorService.java:28)
      at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
      at jenkins.util.ErrorLoggingExecutorService.lambda$wrap$0(ErrorLoggingExecutorService.java:51)
      at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
      at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
      at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
      at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
      at java.base/java.lang.Thread.run(Thread.java:833)

            Unassigned Unassigned
            kjcjohnson Keith Johnson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: