Fix BeanUtils#instantiateClass w/ Kotlin + noarg constructor

Issue: SPR-15851
This commit is contained in:
Sebastien Deleuze
2017-08-14 15:14:02 +02:00
parent f57e5584af
commit ef175d7ca6
2 changed files with 21 additions and 13 deletions

View File

@@ -734,12 +734,11 @@ public abstract class BeanUtils {
* Instantiate a Kotlin class using the provided constructor.
* @param ctor the constructor of the Kotlin class to instantiate
* @param args the constructor arguments to apply (use null for unspecified parameter if needed)
* @throws BeanInstantiationException if no primary constructor can be found
*/
public static <T> T instantiateClass(Constructor<T> ctor, Object... args) {
public static <T> T instantiateClass(Constructor<T> ctor, Object... args) throws IllegalAccessException, InvocationTargetException, InstantiationException {
KFunction<T> kotlinConstructor = ReflectJvmMapping.getKotlinFunction(ctor);
if (kotlinConstructor == null) {
throw new BeanInstantiationException(ctor.getDeclaringClass(), "No corresponding Kotlin constructor found");
return ctor.newInstance(args);
}
List<KParameter> parameters = kotlinConstructor.getParameters();
Map<KParameter, Object> argParameters = new HashMap<>(parameters.size());