ResolvableType equals/hashCode does not consider TypeProvider source
Issue: SPR-14826
(cherry picked from commit be187ba)
This commit is contained in:
@@ -837,7 +837,7 @@ public class ResolvableType implements Serializable {
|
||||
}
|
||||
if (this.typeProvider != otherType.typeProvider &&
|
||||
(this.typeProvider == null || otherType.typeProvider == null ||
|
||||
!ObjectUtils.nullSafeEquals(this.typeProvider.getSource(), otherType.typeProvider.getSource()))) {
|
||||
!ObjectUtils.nullSafeEquals(this.typeProvider.getType(), otherType.typeProvider.getType()))) {
|
||||
return false;
|
||||
}
|
||||
if (this.variableResolver != otherType.variableResolver &&
|
||||
@@ -859,7 +859,7 @@ public class ResolvableType implements Serializable {
|
||||
private int calculateHashCode() {
|
||||
int hashCode = ObjectUtils.nullSafeHashCode(this.type);
|
||||
if (this.typeProvider != null) {
|
||||
hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.typeProvider.getSource());
|
||||
hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.typeProvider.getType());
|
||||
}
|
||||
if (this.variableResolver != null) {
|
||||
hashCode = 31 * hashCode + ObjectUtils.nullSafeHashCode(this.variableResolver.getSource());
|
||||
|
||||
@@ -150,7 +150,7 @@ public class ResolvableTypeTests {
|
||||
|
||||
@Test
|
||||
public void forInstanceProvider() {
|
||||
ResolvableType type = ResolvableType.forInstance(new MyGenericInterfaceType<String>(String.class));
|
||||
ResolvableType type = ResolvableType.forInstance(new MyGenericInterfaceType<>(String.class));
|
||||
assertThat(type.getRawClass(), equalTo(MyGenericInterfaceType.class));
|
||||
assertThat(type.getGeneric().resolve(), equalTo(String.class));
|
||||
}
|
||||
@@ -175,6 +175,14 @@ public class ResolvableTypeTests {
|
||||
ResolvableType type = ResolvableType.forField(field);
|
||||
assertThat(type.getType(), equalTo(field.getGenericType()));
|
||||
assertThat(type.resolve(), equalTo((Class) List.class));
|
||||
|
||||
Field field2 = Fields.class.getDeclaredField("otherPrivateField");
|
||||
ResolvableType type2 = ResolvableType.forField(field2);
|
||||
assertThat(type2.getType(), equalTo(field2.getGenericType()));
|
||||
assertThat(type2.resolve(), equalTo((Class) List.class));
|
||||
|
||||
assertEquals(type, type2);
|
||||
assertEquals(type.hashCode(), type2.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -402,7 +410,7 @@ public class ResolvableTypeTests {
|
||||
public void getInterfaces() throws Exception {
|
||||
ResolvableType type = ResolvableType.forClass(ExtendsList.class);
|
||||
assertThat(type.getInterfaces().length, equalTo(0));
|
||||
SortedSet<String> interfaces = new TreeSet<String>();
|
||||
SortedSet<String> interfaces = new TreeSet<>();
|
||||
for (ResolvableType interfaceType : type.getSuperType().getInterfaces()) {
|
||||
interfaces.add(interfaceType.toString());
|
||||
}
|
||||
@@ -1384,6 +1392,9 @@ public class ResolvableTypeTests {
|
||||
@SuppressWarnings("unused")
|
||||
private List<String> privateField;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private List<String> otherPrivateField;
|
||||
|
||||
public Map<Map<String, Integer>, Map<Byte, Long>> nested;
|
||||
|
||||
public T[] variableTypeGenericArray;
|
||||
|
||||
Reference in New Issue
Block a user