You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Cristian Kalkhoff (JIRA)" <ji...@apache.org> on 2008/11/25 18:15:44 UTC
[jira] Created: (BEANUTILS-332) Getter-/Setter-Detection does not
work on inner default visible level classes
Getter-/Setter-Detection does not work on inner default visible level classes
-----------------------------------------------------------------------------
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: 1.8.0
There seem to be a problem for the BeanUtils copyProperties method, if origin oder destination´s class is only default visible.
I stepped over that when I wrote a unit test, that includes two bean classes with equal properties. I declared them static but not public by accident and wondered why it didn´t worked. After some debugging I found it to fail while checking for readable source and writeable target properties.
See this code sample - Putting public in front of the inner classes static class let it work again:
import junit.framework.TestCase;
public class BeanUtilsTest extends TestCase {
public void testCopyPropertiesObjectObject() {
SourceBean source = new SourceBean();
FullTargetBean fullTarget = new FullTargetBean();
BeanUtils.copyProperties(fullTarget, source);
assertEquals("My World!", fullTarget.getName()); // Fails since it is still "Hello World!"
}
static class SourceBean {
private long id = 10L;
private String name = "My World!";
private Boolean fullMoon = true;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Boolean getFullMoon() {
return fullMoon;
}
public void setFullMoon(Boolean fullMoon) {
this.fullMoon = fullMoon;
}
}
static class FullTargetBean {
private long id = 16L;
private String name = "Hello World!";
private Boolean fullMoon = false;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Boolean isFullMoon() {
return fullMoon;
}
public void setFullMoon(Boolean fullMoon) {
this.fullMoon = fullMoon;
}
}
}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Issue Comment Edited: (BEANUTILS-332)
Getter-/Setter-Detection does not work on inner default visible level
classes
Posted by "Vermeulen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/BEANUTILS-332?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12902801#action_12902801 ]
Vermeulen edited comment on BEANUTILS-332 at 8/26/10 5:48 AM:
--------------------------------------------------------------
I have a similar problem with PropertyUtils.getProperty() on a bean that is of a nested class that is private static. Making the class public static solves the problem. This can be seen in this simple program:
import org.apache.commons.beanutils.PropertyUtils;
public class NestedClassTest {
public static class PublicPerson {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
private static class PrivatePerson {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public static void main(String[] args) throws Exception {
PublicPerson person = new PublicPerson();
person.setName("SlowStrider");
/* Prints 'SlowStrider' */
System.out.println(PropertyUtils.getSimpleProperty(person, "name"));
PrivatePerson person2 = new PrivatePerson();
person.setName("SlowStrider");
/* Throws a NoSuchMethodException */
System.out.println(PropertyUtils.getSimpleProperty(person2, "name"));
}
}
This throws the following exception:
Exception in thread "main" java.lang.NoSuchMethodException: Property 'name' has no getter method in class 'class NestedClassTest$PrivatePerson'
at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1327)
at org.apache.commons.beanutils.PropertyUtils.getSimpleProperty(PropertyUtils.java:611)
at NestedClassTest.main(NestedClassTest.java:36)
was (Author: slowstrider):
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 {
public static class PublicPerson {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
private static class PrivatePerson {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public static void main(String[] args) throws Exception {
PublicPerson person = new PublicPerson();
person.setName("SlowStrider");
// Prints 'SlowStrider'
System.out.println(PropertyUtils.getSimpleProperty(person, "name"));
PrivatePerson person2 = new PrivatePerson();
person.setName("SlowStrider");
// Throws a NoSuchMethodException
System.out.println(PropertyUtils.getSimpleProperty(person2, "name"));
}
}
This throws the following exception:
Exception in thread "main" java.lang.NoSuchMethodException: Property 'name' has no getter method in class 'class NestedClassTest$PrivatePerson'
at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1327)
at org.apache.commons.beanutils.PropertyUtils.getSimpleProperty(PropertyUtils.java:611)
at 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 classes
> -----------------------------------------------------------------------------
>
> 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 origin oder destination´s class is only default visible.
> I stepped over that when I wrote a unit test, that includes two bean classes with equal properties. I declared them static but not public by accident and wondered why it didn´t worked. After some debugging I found it to fail while checking for readable source and writeable target properties.
> See this code sample - Putting public in front of the inner classes static class let it work again:
> import junit.framework.TestCase;
> public class BeanUtilsTest extends TestCase {
> public void testCopyPropertiesObjectObject() {
> SourceBean source = new SourceBean();
> FullTargetBean fullTarget = new FullTargetBean();
> BeanUtils.copyProperties(fullTarget, source);
> assertEquals("My World!", fullTarget.getName()); // Fails since it is still "Hello World!"
> }
> static class SourceBean {
> private long id = 10L;
> private String name = "My World!";
> private Boolean fullMoon = true;
> public long getId() {
> return id;
> }
> public void setId(long id) {
> this.id = id;
> }
> public String getName() {
> return name;
> }
> public void setName(String name) {
> this.name = name;
> }
> public Boolean getFullMoon() {
> return fullMoon;
> }
> public void setFullMoon(Boolean fullMoon) {
> this.fullMoon = fullMoon;
> }
> }
> static class FullTargetBean {
> private long id = 16L;
> private String name = "Hello World!";
> private Boolean fullMoon = false;
> public long getId() {
> return id;
> }
> public void setId(long id) {
> this.id = id;
> }
> public String getName() {
> return name;
> }
> public void setName(String name) {
> this.name = name;
> }
> public Boolean isFullMoon() {
> return fullMoon;
> }
> public void setFullMoon(Boolean fullMoon) {
> this.fullMoon = fullMoon;
> }
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (BEANUTILS-332) Getter-/Setter-Detection does not
work on inner default visible level classes
Posted by "Vermeulen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/BEANUTILS-332?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12902801#action_12902801 ]
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 {
public static class PublicPerson {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
private static class PrivatePerson {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public static void main(String[] args) throws Exception {
PublicPerson person = new PublicPerson();
person.setName("SlowStrider");
// Prints 'SlowStrider'
System.out.println(PropertyUtils.getSimpleProperty(person, "name"));
PrivatePerson person2 = new PrivatePerson();
person.setName("SlowStrider");
// Throws a NoSuchMethodException
System.out.println(PropertyUtils.getSimpleProperty(person2, "name"));
}
}
This throws the following exception:
Exception in thread "main" java.lang.NoSuchMethodException: Property 'name' has no getter method in class 'class NestedClassTest$PrivatePerson'
at org.apache.commons.beanutils.PropertyUtilsBean.getSimpleProperty(PropertyUtilsBean.java:1327)
at org.apache.commons.beanutils.PropertyUtils.getSimpleProperty(PropertyUtils.java:611)
at 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 classes
> -----------------------------------------------------------------------------
>
> 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 origin oder destination´s class is only default visible.
> I stepped over that when I wrote a unit test, that includes two bean classes with equal properties. I declared them static but not public by accident and wondered why it didn´t worked. After some debugging I found it to fail while checking for readable source and writeable target properties.
> See this code sample - Putting public in front of the inner classes static class let it work again:
> import junit.framework.TestCase;
> public class BeanUtilsTest extends TestCase {
> public void testCopyPropertiesObjectObject() {
> SourceBean source = new SourceBean();
> FullTargetBean fullTarget = new FullTargetBean();
> BeanUtils.copyProperties(fullTarget, source);
> assertEquals("My World!", fullTarget.getName()); // Fails since it is still "Hello World!"
> }
> static class SourceBean {
> private long id = 10L;
> private String name = "My World!";
> private Boolean fullMoon = true;
> public long getId() {
> return id;
> }
> public void setId(long id) {
> this.id = id;
> }
> public String getName() {
> return name;
> }
> public void setName(String name) {
> this.name = name;
> }
> public Boolean getFullMoon() {
> return fullMoon;
> }
> public void setFullMoon(Boolean fullMoon) {
> this.fullMoon = fullMoon;
> }
> }
> static class FullTargetBean {
> private long id = 16L;
> private String name = "Hello World!";
> private Boolean fullMoon = false;
> public long getId() {
> return id;
> }
> public void setId(long id) {
> this.id = id;
> }
> public String getName() {
> return name;
> }
> public void setName(String name) {
> this.name = name;
> }
> public Boolean isFullMoon() {
> return fullMoon;
> }
> public void setFullMoon(Boolean fullMoon) {
> this.fullMoon = fullMoon;
> }
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Resolved: (BEANUTILS-332) Getter-/Setter-Detection does not
work on inner default visible level classes
Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/BEANUTILS-332?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Niall Pemberton resolved BEANUTILS-332.
---------------------------------------
Fix Version/s: (was: LATER THAN 1.8.4)
Resolution: Won't Fix
BeanUtils works on public classes & methods. This isn't going to changed
> Getter-/Setter-Detection does not work on inner default visible level classes
> -----------------------------------------------------------------------------
>
> 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
>
> There seem to be a problem for the BeanUtils copyProperties method, if origin oder destination´s class is only default visible.
> I stepped over that when I wrote a unit test, that includes two bean classes with equal properties. I declared them static but not public by accident and wondered why it didn´t worked. After some debugging I found it to fail while checking for readable source and writeable target properties.
> See this code sample - Putting public in front of the inner classes static class let it work again:
> import junit.framework.TestCase;
> public class BeanUtilsTest extends TestCase {
> public void testCopyPropertiesObjectObject() {
> SourceBean source = new SourceBean();
> FullTargetBean fullTarget = new FullTargetBean();
> BeanUtils.copyProperties(fullTarget, source);
> assertEquals("My World!", fullTarget.getName()); // Fails since it is still "Hello World!"
> }
> static class SourceBean {
> private long id = 10L;
> private String name = "My World!";
> private Boolean fullMoon = true;
> public long getId() {
> return id;
> }
> public void setId(long id) {
> this.id = id;
> }
> public String getName() {
> return name;
> }
> public void setName(String name) {
> this.name = name;
> }
> public Boolean getFullMoon() {
> return fullMoon;
> }
> public void setFullMoon(Boolean fullMoon) {
> this.fullMoon = fullMoon;
> }
> }
> static class FullTargetBean {
> private long id = 16L;
> private String name = "Hello World!";
> private Boolean fullMoon = false;
> public long getId() {
> return id;
> }
> public void setId(long id) {
> this.id = id;
> }
> public String getName() {
> return name;
> }
> public void setName(String name) {
> this.name = name;
> }
> public Boolean isFullMoon() {
> return fullMoon;
> }
> public void setFullMoon(Boolean fullMoon) {
> this.fullMoon = fullMoon;
> }
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (BEANUTILS-332) Getter-/Setter-Detection does not
work on inner default visible level classes
Posted by "Vermeulen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/BEANUTILS-332?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12902809#action_12902809 ]
Vermeulen commented on BEANUTILS-332:
-------------------------------------
This issue doesn't seem to be with nested classes but with the class not being public! When I move a Person class to it's own file and make it package scope I get the same error.
> Getter-/Setter-Detection does not work on inner default visible level classes
> -----------------------------------------------------------------------------
>
> 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 origin oder destination´s class is only default visible.
> I stepped over that when I wrote a unit test, that includes two bean classes with equal properties. I declared them static but not public by accident and wondered why it didn´t worked. After some debugging I found it to fail while checking for readable source and writeable target properties.
> See this code sample - Putting public in front of the inner classes static class let it work again:
> import junit.framework.TestCase;
> public class BeanUtilsTest extends TestCase {
> public void testCopyPropertiesObjectObject() {
> SourceBean source = new SourceBean();
> FullTargetBean fullTarget = new FullTargetBean();
> BeanUtils.copyProperties(fullTarget, source);
> assertEquals("My World!", fullTarget.getName()); // Fails since it is still "Hello World!"
> }
> static class SourceBean {
> private long id = 10L;
> private String name = "My World!";
> private Boolean fullMoon = true;
> public long getId() {
> return id;
> }
> public void setId(long id) {
> this.id = id;
> }
> public String getName() {
> return name;
> }
> public void setName(String name) {
> this.name = name;
> }
> public Boolean getFullMoon() {
> return fullMoon;
> }
> public void setFullMoon(Boolean fullMoon) {
> this.fullMoon = fullMoon;
> }
> }
> static class FullTargetBean {
> private long id = 16L;
> private String name = "Hello World!";
> private Boolean fullMoon = false;
> public long getId() {
> return id;
> }
> public void setId(long id) {
> this.id = id;
> }
> public String getName() {
> return name;
> }
> public void setName(String name) {
> this.name = name;
> }
> public Boolean isFullMoon() {
> return fullMoon;
> }
> public void setFullMoon(Boolean fullMoon) {
> this.fullMoon = fullMoon;
> }
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Updated: (BEANUTILS-332) Getter-/Setter-Detection does not
work on inner default visible level classes
Posted by "Niall Pemberton (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/BEANUTILS-332?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Niall Pemberton updated BEANUTILS-332:
--------------------------------------
Fix Version/s: (was: 1.8.0)
LATER THAN 1.8.0
> Getter-/Setter-Detection does not work on inner default visible level classes
> -----------------------------------------------------------------------------
>
> 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.1
>
>
> There seem to be a problem for the BeanUtils copyProperties method, if origin oder destination´s class is only default visible.
> I stepped over that when I wrote a unit test, that includes two bean classes with equal properties. I declared them static but not public by accident and wondered why it didn´t worked. After some debugging I found it to fail while checking for readable source and writeable target properties.
> See this code sample - Putting public in front of the inner classes static class let it work again:
> import junit.framework.TestCase;
> public class BeanUtilsTest extends TestCase {
> public void testCopyPropertiesObjectObject() {
> SourceBean source = new SourceBean();
> FullTargetBean fullTarget = new FullTargetBean();
> BeanUtils.copyProperties(fullTarget, source);
> assertEquals("My World!", fullTarget.getName()); // Fails since it is still "Hello World!"
> }
> static class SourceBean {
> private long id = 10L;
> private String name = "My World!";
> private Boolean fullMoon = true;
> public long getId() {
> return id;
> }
> public void setId(long id) {
> this.id = id;
> }
> public String getName() {
> return name;
> }
> public void setName(String name) {
> this.name = name;
> }
> public Boolean getFullMoon() {
> return fullMoon;
> }
> public void setFullMoon(Boolean fullMoon) {
> this.fullMoon = fullMoon;
> }
> }
> static class FullTargetBean {
> private long id = 16L;
> private String name = "Hello World!";
> private Boolean fullMoon = false;
> public long getId() {
> return id;
> }
> public void setId(long id) {
> this.id = id;
> }
> public String getName() {
> return name;
> }
> public void setName(String name) {
> this.name = name;
> }
> public Boolean isFullMoon() {
> return fullMoon;
> }
> public void setFullMoon(Boolean fullMoon) {
> this.fullMoon = fullMoon;
> }
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Issue Comment Edited: (BEANUTILS-332)
Getter-/Setter-Detection does not work on inner default visible level
classes
Posted by "Vermeulen (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/BEANUTILS-332?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12902809#action_12902809 ]
Vermeulen edited comment on BEANUTILS-332 at 8/26/10 6:23 AM:
--------------------------------------------------------------
This issue doesn't seem to be with nested classes but with the class not being public! When I move a Person class to it's own file and make it default (package) scope I get the same error.
was (Author: slowstrider):
This issue doesn't seem to be with nested classes but with the class not being public! When I move a Person class to it's own file and make it package scope I get the same error.
> Getter-/Setter-Detection does not work on inner default visible level classes
> -----------------------------------------------------------------------------
>
> 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 origin oder destination´s class is only default visible.
> I stepped over that when I wrote a unit test, that includes two bean classes with equal properties. I declared them static but not public by accident and wondered why it didn´t worked. After some debugging I found it to fail while checking for readable source and writeable target properties.
> See this code sample - Putting public in front of the inner classes static class let it work again:
> import junit.framework.TestCase;
> public class BeanUtilsTest extends TestCase {
> public void testCopyPropertiesObjectObject() {
> SourceBean source = new SourceBean();
> FullTargetBean fullTarget = new FullTargetBean();
> BeanUtils.copyProperties(fullTarget, source);
> assertEquals("My World!", fullTarget.getName()); // Fails since it is still "Hello World!"
> }
> static class SourceBean {
> private long id = 10L;
> private String name = "My World!";
> private Boolean fullMoon = true;
> public long getId() {
> return id;
> }
> public void setId(long id) {
> this.id = id;
> }
> public String getName() {
> return name;
> }
> public void setName(String name) {
> this.name = name;
> }
> public Boolean getFullMoon() {
> return fullMoon;
> }
> public void setFullMoon(Boolean fullMoon) {
> this.fullMoon = fullMoon;
> }
> }
> static class FullTargetBean {
> private long id = 16L;
> private String name = "Hello World!";
> private Boolean fullMoon = false;
> public long getId() {
> return id;
> }
> public void setId(long id) {
> this.id = id;
> }
> public String getName() {
> return name;
> }
> public void setName(String name) {
> this.name = name;
> }
> public Boolean isFullMoon() {
> return fullMoon;
> }
> public void setFullMoon(Boolean fullMoon) {
> this.fullMoon = fullMoon;
> }
> }
> }
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.