Skip to content

Commit 8570f60

Browse files
committed
Fixed regression with fallback for non-resolvable property type
1 parent 786e217 commit 8570f60

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

spring-beans/src/test/java/org/springframework/beans/BeanWrapperTests.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,24 @@ public void testPropertyTypeMismatch() {
15771577
assertEquals(8, bwi.getPropertyValue("object"));
15781578
}
15791579

1580+
@Test
1581+
public void testGenericArraySetter() {
1582+
SkipReaderStub foo = new SkipReaderStub();
1583+
BeanWrapperImpl bwi = new BeanWrapperImpl(foo);
1584+
List<String> values = new LinkedList<String>();
1585+
values.add("1");
1586+
values.add("2");
1587+
values.add("3");
1588+
values.add("4");
1589+
bwi.setPropertyValue("items", values);
1590+
Object[] result = foo.items;
1591+
assertEquals(4, result.length);
1592+
assertEquals("1", result[0]);
1593+
assertEquals("2", result[1]);
1594+
assertEquals("3", result[2]);
1595+
assertEquals("4", result[3]);
1596+
}
1597+
15801598

15811599
static class Spr10115Bean {
15821600

@@ -1991,4 +2009,21 @@ public Integer getObject() {
19912009
}
19922010
}
19932011

2012+
2013+
public static class SkipReaderStub<T> {
2014+
2015+
public T[] items;
2016+
2017+
public SkipReaderStub() {
2018+
}
2019+
2020+
public SkipReaderStub(T... items) {
2021+
this.items = items;
2022+
}
2023+
2024+
public void setItems(T... items) {
2025+
this.items = items;
2026+
}
2027+
}
2028+
19942029
}

spring-core/src/main/java/org/springframework/core/ResolvableType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ public Class<?> resolve() {
628628
* Resolve this type to a {@link java.lang.Class}, returning the specified
629629
* {@code fallback} if the type cannot be resolved. This method will consider bounds
630630
* of {@link TypeVariable}s and {@link WildcardType}s if direct resolution fails;
631-
* however, bounds of Object.class will be ignored.
631+
* however, bounds of {@code Object.class} will be ignored.
632632
* @param fallback the fallback class to use if resolution fails (may be {@code null})
633633
* @return the resolved {@link Class} or the {@code fallback}
634634
* @see #resolve()

spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public TypeDescriptor(Field field) {
105105
public TypeDescriptor(Property property) {
106106
Assert.notNull(property, "Property must not be null");
107107
this.resolvableType = ResolvableType.forMethodParameter(property.getMethodParameter());
108-
this.type = this.resolvableType.resolve(Object.class);
108+
this.type = this.resolvableType.resolve(property.getType());
109109
this.annotations = nullSafeAnnotations(property.getAnnotations());
110110
}
111111

0 commit comments

Comments
 (0)