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:
@@ -133,7 +133,12 @@ public class ClassTypeInformation<S> extends TypeDiscoverer<S> {
|
||||
map.put(entry.getKey(), entry.getValue());
|
||||
|
||||
if (value instanceof Class) {
|
||||
map.putAll(getTypeVariableMap((Class<?>) value, visited));
|
||||
|
||||
for (Entry<TypeVariable<?>, Type> nestedEntry : getTypeVariableMap((Class<?>) value, visited).entrySet()) {
|
||||
if (!map.containsKey(nestedEntry.getKey())) {
|
||||
map.put(nestedEntry.getKey(), nestedEntry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user