[
https://issues.apache.org/jira/browse/BEANUTILS-332?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Benedikt Ritter updated BEANUTILS-332:
--------------------------------------
Description:
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:
{code:java}
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;
}
}
}
{code}
was:
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;
}
}
}
> 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: Christian 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:
> {code:java}
> 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;
> }
> }
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)