cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dzmitry Kazimirchyk (JIRA)" <>
Subject [jira] [Closed] (CAY-2064) Issue with BeanAccessor for classes with complex inheritance
Date Fri, 26 Feb 2016 16:13:18 GMT


Dzmitry Kazimirchyk closed CAY-2064.
       Resolution: Fixed
    Fix Version/s: 4.0.M4

I have merge the pull request and added this fix to release notes. Closing.

> Issue with BeanAccessor for classes with complex inheritance
> ------------------------------------------------------------
>                 Key: CAY-2064
>                 URL:
>             Project: Cayenne
>          Issue Type: Bug
>    Affects Versions: 4.0.M3
>            Reporter: Dzmitry Kazimirchyk
>             Fix For: 4.0.M4
> As reported on github per []:
> In certain cases, simply adding an interface to a class with no other changes can break
> For example, consider a HasName interface and a Person entity with a name attribute:
> {code:java}
> public interface HasName {
>     CharSequence getName();
> }
> public class _Person extends CayenneDataObject {
>     public void setName(String name) {
>         writeProperty(NAME_KEY, name);
>     }
>     public String getName() {
>         return (String) readProperty(NAME_KEY);
>     }
> }
> public class Person extends _Person implements HasName {
> }
> {code}
> My only change from the generated classes is to make Person implement HasName. Now, when
I call PropertyUtils.setProperty(person, Person.NAME_KEY, newName), I get a PropertyException:
Property "name" is not writable.
> What's happening is that the compiler is generating a synthetic, no-arg method in Person.class
named "getName" that returns a CharSequence. Since that's the only no-arg method named "getName"
in the class, that's the method returned by Class.getMethod. (It finds a method in the class
and so never checks the super class, per the documentation.) When BeanAccessor looks for the
write method, it looks for setName(CharSequence) instead of setName(String) and comes up empty.

This message was sent by Atlassian JIRA

View raw message