Details

    • Similar Issues:

      Description

      If there is a class in a library as well as some vars and the class's constructor tries to a var from the same library the new()'s result will be the var's result and not a class of the requested type.

       

      Sample code:

      src/com/test/X.groovy:

      package com.test

      public final class X {

          public final String result

          public X(def steps)

      {         if (steps.y())             result = 'y returned TRUE'        else             result = 'y returned FALSE'     }

      }

       

      vars/y.groovy:

      def call()

      {     return false }

       

      Jenkinsfile:

      lib = library 'testLib'

      x = lib.com.test.X(this)

      echo "x = $x"

      echo "result = ${x.result}"

       

      If testLib is set to contain the above code and the Jenkinsfile executed, then it will print:

      x = false

      and throw an exception:

      org.jenkinsci.plugins.scriptsecurity.sandbox.RejectedAccessException: No such field found: field java.lang.Boolean result

       

      Calling into vars from other class methods seems to work fine.

        Attachments

          Activity

          Hide
          szabi_tolnai Szabolcs Tolnai added a comment -

          It turns out that this isn't just when calling a vars from the same library but any call into the script passed through the steps parameter. The result of the new() will be the result of the first call into any of the steps's methods.

          Show
          szabi_tolnai Szabolcs Tolnai added a comment - It turns out that this isn't just when calling a vars from the same library but any call into the script passed through the steps parameter. The result of the new() will be the result of the first call into any of the steps's methods.

            People

            • Assignee:
              Unassigned
              Reporter:
              szabi_tolnai Szabolcs Tolnai
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: