groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Miro Bezjak <bezjak.m...@gmail.com>
Subject Groovy doesn't follow java beans specification on certain edge cases?
Date Fri, 29 May 2015 13:32:56 GMT
Tested with groovy 2.4.3 and 2.1.8.

--------------------------------------
class Foo {
    String c
    String cxName
    String cName
}
new java.beans.PropertyDescriptor('c', Foo) // ok
new java.beans.PropertyDescriptor('cxName', Foo) // ok
new java.beans.PropertyDescriptor('cName', Foo) //
java.beans.IntrospectionException: Method not found: isCName
--------------------------------------

Looking at AST in finalization, for the last case (cName), groovy generates:
--------------------------------------
 public java.lang.String getcName() {
}

public void setcName(java.lang.String value) {
}
--------------------------------------

Shouldn't it generate `getCName` and `setCName` instead?


As far as I can see, this only affects java.beans. The following example
works without any problem:
--------------------------------------
class Foo {
    String cName
}

def f = new Foo()
f.cName = 'abc'
println f.cName // abc
--------------------------------------


One workaround is to define proper getter and setter:
--------------------------------------
class Foo {
    String cName

    String getCName() { cName }
    void setCName(String cName) { this.cName = cName }
}

new java.beans.PropertyDescriptor('cName', Foo) // ok now
--------------------------------------

Mime
View raw message