Skip to content

Commit 63c8e7c

Browse files
committedMar 6, 2025
Restore lenient matching of unresolved nested bound
Closes gh-34541
1 parent c5ecc50 commit 63c8e7c

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed
 

Diff for: ‎spring-core/src/main/java/org/springframework/core/ResolvableType.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ else if (upUntilUnresolvable) {
343343
return otherBounds.isAssignableFrom(this, matchedBefore);
344344
}
345345
else if (!strict) {
346-
return (matchedBefore != null ? otherBounds.equalsType(this) :
346+
return (matchedBefore != null ? otherBounds.equalsType(this, matchedBefore) :
347347
otherBounds.isAssignableTo(this, matchedBefore));
348348
}
349349
else {
@@ -1794,11 +1794,13 @@ public boolean isAssignableTo(ResolvableType type, @Nullable Map<Type, Type> mat
17941794
* Return {@code true} if these bounds are equal to the specified type.
17951795
* @param type the type to test against
17961796
* @return {@code true} if these bounds are equal to the type
1797-
* @since 6.2.3
1797+
* @since 6.2.4
17981798
*/
1799-
public boolean equalsType(ResolvableType type) {
1799+
public boolean equalsType(ResolvableType type, @Nullable Map<Type, Type> matchedBefore) {
18001800
for (ResolvableType bound : this.bounds) {
1801-
if (!type.equalsType(bound)) {
1801+
if (this.kind == Kind.UPPER && bound.hasUnresolvableGenerics() ?
1802+
!type.isAssignableFrom(bound, true, matchedBefore, false) :
1803+
!type.equalsType(bound)) {
18021804
return false;
18031805
}
18041806
}

Diff for: ‎spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java

+18
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,12 @@ void gh33535() throws Exception {
15271527
assertThat(repository3.isAssignableFromResolvedPart(repository2)).isTrue();
15281528
}
15291529

1530+
@Test
1531+
void gh34541() throws Exception {
1532+
ResolvableType typeWithGenerics = ResolvableType.forField(getClass().getDeclaredField("paymentCreator"));
1533+
assertThat(typeWithGenerics.isAssignableFrom(PaymentCreator.class)).isTrue();
1534+
}
1535+
15301536

15311537
private ResolvableType testSerialization(ResolvableType type) throws Exception {
15321538
ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -1928,6 +1934,18 @@ static class RecursiveMapWithInterface extends HashMap<String, RecursiveMapWithI
19281934
}
19291935

19301936

1937+
PaymentCreator<? extends Payment, PaymentCreatorParameter<? extends Payment>> paymentCreator;
1938+
1939+
static class PaymentCreator<T extends Payment, P extends PaymentCreatorParameter<T>> {
1940+
}
1941+
1942+
static class PaymentCreatorParameter<T extends Payment> {
1943+
}
1944+
1945+
abstract static class Payment {
1946+
}
1947+
1948+
19311949
private static class ResolvableTypeAssert extends AbstractAssert<ResolvableTypeAssert, ResolvableType>{
19321950

19331951
public ResolvableTypeAssert(ResolvableType actual) {

0 commit comments

Comments
 (0)