-
Bug
-
Resolution: Unresolved
-
Major
-
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()
Not sure if this is a bug or not. def field looks wrong. To declare a field, you would either state a type (String field) or use @groovy.transform.Field field. What def field—declaring a local variable—does when in the body of a class I have no idea.