diff --git a/spring-core/src/main/java/org/springframework/core/ResolvableType.java b/spring-core/src/main/java/org/springframework/core/ResolvableType.java index 079ccfac3a79..18f8fd45b872 100644 --- a/spring-core/src/main/java/org/springframework/core/ResolvableType.java +++ b/spring-core/src/main/java/org/springframework/core/ResolvableType.java @@ -1013,7 +1013,7 @@ public boolean isAssignableFrom(Class other) { } @Override public boolean isAssignableFrom(ResolvableType other) { - Class otherClass = other.getRawClass(); + Class otherClass = other.resolve(); return (otherClass != null && (clazz == null || ClassUtils.isAssignable(clazz, otherClass))); } }; diff --git a/spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java b/spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java index 192d54d0eda5..2aa22920ac5f 100644 --- a/spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java +++ b/spring-core/src/test/java/org/springframework/core/ResolvableTypeTests.java @@ -134,6 +134,18 @@ public void forRawClassWithNull() throws Exception { assertThat(type.isAssignableFrom(String.class)).isTrue(); } + @Test + public void forRawClassAssignableFromTypeVariable() { // gh-23321 + ResolvableType typeVariable = ResolvableType.forClass(ExtendsList.class).as(List.class).getGeneric(); + ResolvableType raw = ResolvableType.forRawClass(CharSequence.class); + assertThat(raw.resolve()).isEqualTo(CharSequence.class); + assertThat(typeVariable.resolve()).isEqualTo(CharSequence.class); + assertThat(raw.resolve().isAssignableFrom(typeVariable.resolve())).isTrue(); + assertThat(typeVariable.resolve().isAssignableFrom(raw.resolve())).isTrue(); + assertThat(raw.isAssignableFrom(typeVariable)).isTrue(); + assertThat(typeVariable.isAssignableFrom(raw)).isTrue(); + } + @Test public void forInstanceMustNotBeNull() { assertThatIllegalArgumentException().isThrownBy(() ->