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

Shared Library child class no such field exception

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Major Major
    • workflow-cps-plugin
    • None
    • Jenkins 2.46.2
      Pipeline: Shared Groovy Libraries 2.8
      Pipeline: API 2.3

      In a shared library, I have a super class with one field and a getter/setter for it.  I then have a child class which extends the super class and does nothing else.  If I instantiate an instance of the child class in the pipeline and then call the setter/getter method from the super class I get a "groovy.lang.MissingFieldException: No such field: field" error.

      If I compile and test this with gradle, it compiles and runs just fine.  Either I missed something in how the pipeline compiler works or it's a bug.  Please let me know if there's another method I should use in this scenario.

       

      Parent Class

      class B implements Serializable {

      def field;

      def getField() {
        return field
      }

      def setField(value) {
        field = value
      }

      }

       

      Child Class

      class A extends B {

      }

       

      Pipeline

      def b = new B()
      def a = new A()

      b.setField('test b')

      // Error occurs when pipeline calls a.setField because it can't find the field in its super class
      a.setField('test a')

      echo b.getField()
      echo a.getField()

          [JENKINS-44183] Shared Library child class no such field exception

          Corey Mead created issue -
          Corey Mead made changes -
          Description Original: In a shared library, I have a super class with one field and a getter/setter for it.  I then have a child class which extends the super class and does nothing else.  If I instantiate an instance of the child class in the pipeline and then call the setter/getter method from the super class I get a 
          groovy.lang.MissingFieldException: No such field: field error.
          If I compile and test this with gradle, it compiles and runs just fine.  Either I missed something in how the pipeline compiler works or it's a bug.  Please let me know if there's another method I should use in this scenario.

           

          *Parent Class*

          class B implements Serializable \{

          def field;

          def getField() \{
            return field
           }

          def setField(value) \{
            field = value
           }


          }

           

          *Child Class*

          class A extends B \{
           
          }

           

          *Pipeline*

          def b = new B()
          def a = new A()

          b.setField('test b')

          // Error occurs when pipeline calls a.setField because it can't find the field in its super class
          a.setField('test a')

          echo b.getField()
          echo a.getField()
          New: In a shared library, I have a super class with one field and a getter/setter for it.  I then have a child class which extends the super class and does nothing else.  If I instantiate an instance of the child class in the pipeline and then call the setter/getter method from the super class I get a "groovy.lang.MissingFieldException: No such field: field" error.


           If I compile and test this with gradle, it compiles and runs just fine.  Either I missed something in how the pipeline compiler works or it's a bug.  Please let me know if there's another method I should use in this scenario.

           

          *Parent Class*

          class B implements Serializable \{

          def field;

          def getField() \{
             return field
           }

          def setField(value) \{
             field = value
           }

          }

           

          *Child Class*

          class A extends B \{

          }

           

          *Pipeline*

          def b = new B()
           def a = new A()

          b.setField('test b')

          // Error occurs when pipeline calls a.setField because it can't find the field in its super class
           a.setField('test a')

          echo b.getField()
           echo a.getField()
          Jesse Glick made changes -
          Component/s Original: pipeline [ 21692 ]

            Unassigned Unassigned
            cjmead Corey Mead
            Votes:
            3 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: