Skip to content

Commit

Permalink
Skip comparing variableResolver if underlying type is Class
Browse files Browse the repository at this point in the history
Before this commit, given:
```java
ResolvableType type1 = ResolvableType.forClassWithGenerics(IProvider.class, String.class);
ResolvableType type2 = ResolvableType.forClassWithGenerics(IProvider.class,ResolvableType.forClass(StringProvider.class).as(IProvider.class).getGenerics());
assertThat(type1).isEqualTo(type2);
```
will cause:
```
Expected :org.springframework.core.ResolvableTypeTests$IProvider<java.lang.String>
Actual   :org.springframework.core.ResolvableTypeTests$IProvider<java.lang.String>
```
  • Loading branch information
quaff committed Mar 22, 2024
1 parent b1b9ee0 commit e9a9e19
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ public boolean equals(@Nullable Object other) {
!ObjectUtils.nullSafeEquals(this.typeProvider.getType(), otherType.typeProvider.getType()))) {
return false;
}
if (this.variableResolver != otherType.variableResolver &&
if (!(this.type instanceof Class<?>) && this.variableResolver != otherType.variableResolver &&
(this.variableResolver == null || otherType.variableResolver == null ||
!ObjectUtils.nullSafeEquals(this.variableResolver.getSource(), otherType.variableResolver.getSource()))) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,13 @@ void gh32327() throws Exception {
assertThat(repository3.isAssignableFromResolvedPart(repository1)).isFalse();
}

@Test
void skipComparingVariableResolverIfUnderlyingTypeIsClass() {
ResolvableType type1 = ResolvableType.forClassWithGenerics(IProvider.class, String.class);
ResolvableType type2 = ResolvableType.forClassWithGenerics(IProvider.class,
ResolvableType.forClass(StringProvider.class).as(IProvider.class).getGenerics());
assertThat(type1).isEqualTo(type2);
}

private ResolvableType testSerialization(ResolvableType type) throws Exception {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Expand Down Expand Up @@ -1719,6 +1726,9 @@ class TypedInnerTyped extends InnerTyped<Long> {
public interface IProvider<P> {
}

public interface StringProvider extends IProvider<String> {
}

public interface IBase<BT extends IBase<BT>> {
}

Expand Down

0 comments on commit e9a9e19

Please sign in to comment.