Fixed primitive type assignability in BeanUtils.copyProperties

Issue: SPR-11231
This commit is contained in:
Juergen Hoeller 2013-12-16 20:18:37 +01:00
parent 9eb58b9596
commit 8a3b4c69c8
2 changed files with 25 additions and 1 deletions

View File

@ -600,7 +600,7 @@ public abstract class BeanUtils {
if (sourcePd != null) {
Method readMethod = sourcePd.getReadMethod();
if (readMethod != null &&
writeMethod.getParameterTypes()[0].isAssignableFrom(readMethod.getReturnType())) {
ClassUtils.isAssignable(writeMethod.getParameterTypes()[0], readMethod.getReturnType())) {
try {
if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {
readMethod.setAccessible(true);

View File

@ -189,9 +189,13 @@ public final class BeanUtilsTests {
public void testCopyPropertiesWithInvalidProperty() {
InvalidProperty source = new InvalidProperty();
source.setName("name");
source.setFlag1(true);
source.setFlag2(true);
InvalidProperty target = new InvalidProperty();
BeanUtils.copyProperties(source, target);
assertEquals(target.getName(), "name");
assertTrue(target.getFlag1());
assertTrue(target.getFlag2());
}
@Test
@ -308,6 +312,10 @@ public final class BeanUtilsTests {
private String value;
private boolean flag1;
private boolean flag2;
public void setName(String name) {
this.name = name;
}
@ -323,6 +331,22 @@ public final class BeanUtilsTests {
public String getValue() {
return this.value;
}
public void setFlag1(boolean flag1) {
this.flag1 = flag1;
}
public Boolean getFlag1() {
return this.flag1;
}
public void setFlag2(Boolean flag2) {
this.flag2 = flag2;
}
public boolean getFlag2() {
return this.flag2;
}
}