Fix Kotlin inner class nested configuration handling

Before this commit, Kotlin inner class nested configuration
handling thrown an IndexOutOfBoundsException due to bogus filtering
of its constructor parameter reference to an instance of the outer
class.

This commit keep constructor parameter of type INSTANCE in order to
throw a more meaningful NoSuchBeanDefinitionException.

Issue: SPR-17222
This commit is contained in:
Sebastien Deleuze
2018-09-07 11:17:52 +02:00
parent c8627c05ed
commit 8d45e3e7ef
3 changed files with 50 additions and 23 deletions

View File

@@ -29,6 +29,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import kotlin.reflect.KFunction;
@@ -768,17 +769,21 @@ public class MethodParameter {
}
else {
KFunction<?> function = null;
Predicate<KParameter> predicate = null;
if (method != null) {
function = ReflectJvmMapping.getKotlinFunction(method);
predicate = p -> KParameter.Kind.VALUE.equals(p.getKind());
}
else if (ctor != null) {
function = ReflectJvmMapping.getKotlinFunction(ctor);
predicate = p -> KParameter.Kind.VALUE.equals(p.getKind()) ||
KParameter.Kind.INSTANCE.equals(p.getKind());
}
if (function != null) {
List<KParameter> parameters = function.getParameters();
KParameter parameter = parameters
.stream()
.filter(p -> KParameter.Kind.VALUE.equals(p.getKind()))
.filter(predicate)
.collect(Collectors.toList())
.get(index);
return (parameter.getType().isMarkedNullable() || parameter.isOptional());