Collect constructor type information via Constructor.getParameters().

This commit fixes an issue where we fail to detect all type arguments from a given constructor. calling getGenericParameterTypes in some cases does not include all Types, we now explicitly iterate over the parameters and extract the parameterized type that is used for creating the TypeInformation.

Closes: #2313
Original pull request: #2314.
This commit is contained in:
Christoph Strobl
2021-02-25 10:24:32 +01:00
committed by Mark Paluch
parent f3dfd0b52c
commit 8917115ba9
2 changed files with 48 additions and 7 deletions

View File

@@ -20,6 +20,7 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
@@ -175,14 +176,11 @@ class TypeDiscoverer<S> implements TypeInformation<S> {
Assert.notNull(constructor, "Constructor must not be null!");
Type[] types = constructor.getGenericParameterTypes();
List<TypeInformation<?>> result = new ArrayList<>(types.length);
for (Type parameterType : types) {
result.add(createInfo(parameterType));
List<TypeInformation<?>> parameterTypes = new ArrayList<>(constructor.getParameterCount());
for(Parameter parameter : constructor.getParameters()) {
parameterTypes.add(createInfo(parameter.getParameterizedType()));
}
return result;
return parameterTypes;
}
/*