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:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user