[ 
https://issues.apache.org/jira/browse/CAY-2064?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

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: https://issues.apache.org/jira/browse/CAY-2064
>             Project: Cayenne
>          Issue Type: Bug
>    Affects Versions: 4.0.M3
>            Reporter: Dzmitry Kazimirchyk
>             Fix For: 4.0.M4
>
>
> As reported on github per [https://github.com/apache/cayenne/pull/87]:
> In certain cases, simply adding an interface to a class with no other changes 
> can break PropertyUtils.setProperty.
> 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
(v6.3.4#6332)

Reply via email to