DATACMNS-896 - Improved detection of type variable mappings in recursively nested generics.

If the same generic type was used on recursively nested generics declarations, like this:

class GenericType<T> {}

class Nested extends GenericType<String> {}

class Concrete extends GenericType<Nested> {}

our traversal of the generics discovered T bound to String in Nested and as that is extending GenericType as well, the T detected here is the same instance as the T within the map discovered for Concrete. As we previously added the nested types after we added the original entry, the nested discovery overwrote the more local one.

We now make sure the detected nested type variable mappings don't overwrite already existing ones.
This commit is contained in:
Oliver Gierke
2016-08-20 19:49:18 +02:00
parent f75320f33c
commit 4fa84fc983
2 changed files with 28 additions and 2 deletions

View File

@@ -106,7 +106,7 @@ public class ClassTypeInformationUnitTests {
property = information.getProperty("rawSet");
assertEquals(Set.class, property.getType());
assertThat(property.getComponentType().getType(), is(Matchers.<Class<?>> equalTo(Object.class)));
assertThat(property.getComponentType().getType(), is(Matchers.<Class<?>>equalTo(Object.class)));
assertNull(property.getMapValueType());
}
@@ -402,6 +402,17 @@ public class ClassTypeInformationUnitTests {
assertThat(left.hashCode(), is(right.hashCode()));
}
/**
* @see DATACMNS-896
*/
@Test
public void prefersLocalTypeMappingOverNestedWithSameGenericType() {
ClassTypeInformation<Concrete> information = ClassTypeInformation.from(Concrete.class);
assertThat(information.getProperty("field").getType(), is(typeCompatibleWith(Nested.class)));
}
static class StringMapContainer extends MapContainer<String> {
}
@@ -590,4 +601,14 @@ public class ClassTypeInformationUnitTests {
T field;
S anotherField;
}
// DATACMNS-896
static class SomeType<T> {
T field;
}
static class Nested extends SomeType<String> {}
static class Concrete extends SomeType<Nested> {}
}