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

Numeric increment operator does not work in a closure in an sandbox

    XMLWordPrintable

Details

    Description

      The following fails in a sandbox

      def lst = [1,2,3,4];
      def int count = 0
      lst.findAll {
          count++
      }
      

      with the exception

      groovy.lang.MissingMethodException: No signature of method: Script1.next() is applicable for argument types: () values: []
      Possible solutions: wait(), wait(long), getAt(java.lang.String), inject(groovy.lang.Closure), wait(long, int), inject(java.lang.Object, groovy.lang.Closure)
      	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:58)
      	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:64)
      	at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:54)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
      	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:155)
      	at org.kohsuke.groovy.sandbox.GroovyInterceptor.onMethodCall(GroovyInterceptor.java:23)
      	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:123)
      	at org.jenkinsci.plugins.scriptsecurity.sandbox.groovy.SandboxInterceptor.onMethodCall(SandboxInterceptor.java:110)
      	at org.kohsuke.groovy.sandbox.impl.Checker$1.call(Checker.java:153)
      	at org.kohsuke.groovy.sandbox.impl.Checker.checkedCall(Checker.java:157)
      	at org.kohsuke.groovy.sandbox.impl.Checker$checkedCall$0.callStatic(Unknown Source)
      	at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56)
      	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194)
      	at Script1$_run_closure1.doCall(Script1.groovy:4)

      The workaround is to avoid the increment operator

      def lst = [1,2,3,4];
      def int count = 0
      lst.findAll {
          count = count + 1
      }
      

      Whilst the workaround is easy enough to apply it's not intuitive.

      Solution: Either fix, or perhaps a document describing known issues and basic coding constructs that need to be avoided when running in a sandbox?

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              pwiseman Peter Wiseman
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: