DATACMNS-855 - Prevent memory leak in SyntheticParameterizedType.
Added proper equals(…) and hashCode() methods to SyntheticParameterizedType to make sure instances created for the same type information and type parameters are considered equal.
This commit is contained in:
@@ -609,5 +609,40 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!(obj instanceof SyntheticParamterizedType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
SyntheticParamterizedType that = (SyntheticParamterizedType) obj;
|
||||
|
||||
return this.typeInformation.equals(that.typeInformation) && this.typeParameters.equals(that.typeParameters);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
|
||||
int result = 17;
|
||||
|
||||
result += 31 * typeInformation.hashCode();
|
||||
result += 31 * typeParameters.hashCode();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -382,6 +382,24 @@ public class ClassTypeInformationUnitTests {
|
||||
assertThat(property.specialize(from), is((TypeInformation) from));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATACMNS-855
|
||||
*/
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void specializedTypeEqualsAndHashCode() {
|
||||
|
||||
ClassTypeInformation<Foo> root = ClassTypeInformation.from(Foo.class);
|
||||
TypeInformation<?> property = root.getProperty("abstractBar");
|
||||
|
||||
TypeInformation left = property.specialize(ClassTypeInformation.from(Bar.class));
|
||||
TypeInformation right = property.specialize(ClassTypeInformation.from(Bar.class));
|
||||
|
||||
assertThat(left, is(right));
|
||||
assertThat(right, is(left));
|
||||
assertThat(left.hashCode(), is(right.hashCode()));
|
||||
}
|
||||
|
||||
static class StringMapContainer extends MapContainer<String> {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user