Return-Path: Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: (qmail 45633 invoked from network); 26 Aug 2010 09:46:22 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 26 Aug 2010 09:46:22 -0000 Received: (qmail 68971 invoked by uid 500); 26 Aug 2010 09:46:21 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 68586 invoked by uid 500); 26 Aug 2010 09:46:19 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 68578 invoked by uid 99); 26 Aug 2010 09:46:19 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Aug 2010 09:46:19 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.22] (HELO thor.apache.org) (140.211.11.22) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 26 Aug 2010 09:46:16 +0000 Received: from thor (localhost [127.0.0.1]) by thor.apache.org (8.13.8+Sun/8.13.8) with ESMTP id o7Q9jsbd003034 for ; Thu, 26 Aug 2010 09:45:54 GMT Message-ID: <31877502.2191282815954550.JavaMail.jira@thor> Date: Thu, 26 Aug 2010 05:45:54 -0400 (EDT) From: "Vermeulen (JIRA)" To: issues@commons.apache.org Subject: [jira] Commented: (BEANUTILS-332) Getter-/Setter-Detection does not work on inner default visible level classes In-Reply-To: <99280187.1227633344307.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/BEANUTILS-332?page=3Dcom.atlass= ian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D1= 2902801#action_12902801 ]=20 Vermeulen commented on BEANUTILS-332: ------------------------------------- I have a similar problem with PropertyUtils.getProperty() on a bean that is= of a nested class that is private static: import org.apache.commons.beanutils.PropertyUtils; public class NestedClassTest { =09public static class PublicPerson { =09=09private String name; =09=09public String getName() { =09=09=09return name; =09=09} =09=09public void setName(String name) { =09=09=09this.name =3D name; =09=09} =09} =09private static class PrivatePerson { =09=09private String name; =09=09public String getName() { =09=09=09return name; =09=09} =09=09public void setName(String name) { =09=09=09this.name =3D name; =09=09} =09} =09public static void main(String[] args) throws Exception { =09=09PublicPerson person =3D new PublicPerson(); =09=09person.setName("SlowStrider"); =09=09// Prints 'SlowStrider' =09=09System.out.println(PropertyUtils.getSimpleProperty(person, "name")); =09=09PrivatePerson person2 =3D new PrivatePerson(); =09=09person.setName("SlowStrider"); =09=09// Throws a NoSuchMethodException =09=09System.out.println(PropertyUtils.getSimpleProperty(person2, "name")); =09} } This throws the following exception: Exception in thread "main" java.lang.NoSuchMethodException: Property 'name'= has no getter method in class 'class NestedClassTest$PrivatePerson' =09at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(Prop= ertyUtilsBean.java:1327) =09at org.apache.commons.beanutils.PropertyUtils.getSimpleProperty(Property= Utils.java:611) =09at NestedClassTest.main(NestedClassTest.java:37) Making the Person class public static solves the problem! > Getter-/Setter-Detection does not work on inner default visible level cla= sses > -------------------------------------------------------------------------= ---- > > Key: BEANUTILS-332 > URL: https://issues.apache.org/jira/browse/BEANUTILS-332 > Project: Commons BeanUtils > Issue Type: Bug > Components: Bean / Property Utils > Affects Versions: 1.8.0 > Environment: Linux, Java 1.5 > Reporter: Cristian Kalkhoff > Fix For: LATER THAN 1.8.4 > > > There seem to be a problem for the BeanUtils copyProperties method, if or= igin oder destination=C2=B4s class is only default visible. > I stepped over that when I wrote a unit test, that includes two bean clas= ses with equal properties. I declared them static but not public by acciden= t and wondered why it didn=C2=B4t worked. After some debugging I found it t= o fail while checking for readable source and writeable target properties. > See this code sample - Putting public in front of the inner classes stati= c class let it work again: > import junit.framework.TestCase; > public class BeanUtilsTest extends TestCase { > public void testCopyPropertiesObjectObject() { > =09SourceBean source =3D new SourceBean(); > =09FullTargetBean fullTarget =3D new FullTargetBean(); > =09BeanUtils.copyProperties(fullTarget, source); > =09assertEquals("My World!", fullTarget.getName()); // Fails since it is = still "Hello World!" > } > static class SourceBean { > =09private long id =3D 10L; > =09private String name =3D "My World!"; > =09private Boolean fullMoon =3D true; > =09public long getId() { > =09 return id; > =09} > =09public void setId(long id) { > =09 this.id =3D id; > =09} > =09public String getName() { > =09 return name; > =09} > =09public void setName(String name) { > =09 this.name =3D name; > =09} > =09public Boolean getFullMoon() { > =09 return fullMoon; > =09} > =09public void setFullMoon(Boolean fullMoon) { > =09 this.fullMoon =3D fullMoon; > =09} > } > static class FullTargetBean { > =09private long id =3D 16L; > =09private String name =3D "Hello World!"; > =09private Boolean fullMoon =3D false; > =09public long getId() { > =09 return id; > =09} > =09public void setId(long id) { > =09 this.id =3D id; > =09} > =09public String getName() { > =09 return name; > =09} > =09public void setName(String name) { > =09 this.name =3D name; > =09} > =09public Boolean isFullMoon() { > =09 return fullMoon; > =09} > =09public void setFullMoon(Boolean fullMoon) { > =09 this.fullMoon =3D fullMoon; > =09} > } > } --=20 This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.