Fixed primitive type assignability in BeanUtils.copyProperties
Issue: SPR-11231
This commit is contained in:
parent
9eb58b9596
commit
8a3b4c69c8
|
|
@ -600,7 +600,7 @@ public abstract class BeanUtils {
|
||||||
if (sourcePd != null) {
|
if (sourcePd != null) {
|
||||||
Method readMethod = sourcePd.getReadMethod();
|
Method readMethod = sourcePd.getReadMethod();
|
||||||
if (readMethod != null &&
|
if (readMethod != null &&
|
||||||
writeMethod.getParameterTypes()[0].isAssignableFrom(readMethod.getReturnType())) {
|
ClassUtils.isAssignable(writeMethod.getParameterTypes()[0], readMethod.getReturnType())) {
|
||||||
try {
|
try {
|
||||||
if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {
|
if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) {
|
||||||
readMethod.setAccessible(true);
|
readMethod.setAccessible(true);
|
||||||
|
|
|
||||||
|
|
@ -189,9 +189,13 @@ public final class BeanUtilsTests {
|
||||||
public void testCopyPropertiesWithInvalidProperty() {
|
public void testCopyPropertiesWithInvalidProperty() {
|
||||||
InvalidProperty source = new InvalidProperty();
|
InvalidProperty source = new InvalidProperty();
|
||||||
source.setName("name");
|
source.setName("name");
|
||||||
|
source.setFlag1(true);
|
||||||
|
source.setFlag2(true);
|
||||||
InvalidProperty target = new InvalidProperty();
|
InvalidProperty target = new InvalidProperty();
|
||||||
BeanUtils.copyProperties(source, target);
|
BeanUtils.copyProperties(source, target);
|
||||||
assertEquals(target.getName(), "name");
|
assertEquals(target.getName(), "name");
|
||||||
|
assertTrue(target.getFlag1());
|
||||||
|
assertTrue(target.getFlag2());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
@ -308,6 +312,10 @@ public final class BeanUtilsTests {
|
||||||
|
|
||||||
private String value;
|
private String value;
|
||||||
|
|
||||||
|
private boolean flag1;
|
||||||
|
|
||||||
|
private boolean flag2;
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
@ -323,6 +331,22 @@ public final class BeanUtilsTests {
|
||||||
public String getValue() {
|
public String getValue() {
|
||||||
return this.value;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue