diff --git a/src/main/java/org/springframework/data/util/TypeDiscoverer.java b/src/main/java/org/springframework/data/util/TypeDiscoverer.java index 9f587e498..8877b1d6c 100644 --- a/src/main/java/org/springframework/data/util/TypeDiscoverer.java +++ b/src/main/java/org/springframework/data/util/TypeDiscoverer.java @@ -15,6 +15,10 @@ */ package org.springframework.data.util; +import lombok.EqualsAndHashCode; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; + import java.beans.PropertyDescriptor; import java.lang.reflect.Constructor; import java.lang.reflect.Field; @@ -558,23 +562,12 @@ class TypeDiscoverer implements TypeInformation { * @author Oliver Gierke * @since 1.11 */ + @EqualsAndHashCode + @RequiredArgsConstructor private static class SyntheticParamterizedType implements ParameterizedType { - private final ClassTypeInformation typeInformation; - private final List> typeParameters; - - /** - * @param typeInformation must not be {@literal null}. - * @param typeParameters must not be {@literal null}. - */ - public SyntheticParamterizedType(ClassTypeInformation typeInformation, List> typeParameters) { - - Assert.notNull(typeInformation, "Type must not be null!"); - Assert.notNull(typeParameters, "Type parameters must not be null!"); - - this.typeInformation = typeInformation; - this.typeParameters = typeParameters; - } + private final @NonNull ClassTypeInformation typeInformation; + private final @NonNull List> typeParameters; /* * (non-Javadoc) diff --git a/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java b/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java index ef1ef5355..83169819c 100644 --- a/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java +++ b/src/test/java/org/springframework/data/util/ClassTypeInformationUnitTests.java @@ -382,6 +382,24 @@ public class ClassTypeInformationUnitTests { assertThat(property.specialize(from), is((TypeInformation) from)); } + /** + * @see DATACMNS-855 + */ + @Test + @SuppressWarnings("rawtypes") + public void specializedTypeEqualsAndHashCode() { + + ClassTypeInformation 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 { }