Support non-standard classes in Kotlin reflection discovery methods
Issue: SPR-15999
This commit is contained in:
parent
65f556c0e2
commit
3996f33399
|
@ -735,14 +735,19 @@ public abstract class BeanUtils {
|
|||
*/
|
||||
@Nullable
|
||||
public static <T> Constructor<T> findPrimaryConstructor(Class<T> clazz) {
|
||||
KFunction<T> primaryConstructor = KClasses.getPrimaryConstructor(JvmClassMappingKt.getKotlinClass(clazz));
|
||||
if (primaryConstructor == null) {
|
||||
try {
|
||||
KFunction<T> primaryConstructor = KClasses.getPrimaryConstructor(JvmClassMappingKt.getKotlinClass(clazz));
|
||||
if (primaryConstructor == null) {
|
||||
return null;
|
||||
}
|
||||
Constructor<T> constructor = ReflectJvmMapping.getJavaConstructor(primaryConstructor);
|
||||
Assert.notNull(constructor,
|
||||
() -> "Failed to find Java constructor corresponding to Kotlin primary constructor: " + clazz.getName());
|
||||
return constructor;
|
||||
}
|
||||
catch (UnsupportedOperationException ex) {
|
||||
return null;
|
||||
}
|
||||
Constructor<T> constructor = ReflectJvmMapping.getJavaConstructor(primaryConstructor);
|
||||
Assert.notNull(constructor,
|
||||
() -> "Failed to find Java constructor corresponding to Kotlin primary constructor: " + clazz.getName());
|
||||
return constructor;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -781,13 +781,18 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
|
|||
*/
|
||||
@Nullable
|
||||
public static <T> Constructor<T> findPrimaryConstructor(Class<T> clazz) {
|
||||
KFunction<T> primaryConstructor = KClasses.getPrimaryConstructor(JvmClassMappingKt.getKotlinClass(clazz));
|
||||
if (primaryConstructor == null) {
|
||||
try {
|
||||
KFunction<T> primaryConstructor = KClasses.getPrimaryConstructor(JvmClassMappingKt.getKotlinClass(clazz));
|
||||
if (primaryConstructor == null) {
|
||||
return null;
|
||||
}
|
||||
Constructor<T> constructor = ReflectJvmMapping.getJavaConstructor(primaryConstructor);
|
||||
Assert.notNull(constructor, "Can't get the Java constructor corresponding to the Kotlin primary constructor of " + clazz.getName());
|
||||
return constructor;
|
||||
}
|
||||
catch (UnsupportedOperationException ex) {
|
||||
return null;
|
||||
}
|
||||
Constructor<T> constructor = ReflectJvmMapping.getJavaConstructor(primaryConstructor);
|
||||
Assert.notNull(constructor, "Can't get the Java constructor corresponding to the Kotlin primary constructor of " + clazz.getName());
|
||||
return constructor;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -62,8 +62,13 @@ public class KotlinReflectionParameterNameDiscoverer implements ParameterNameDis
|
|||
if (!useKotlinSupport(method.getDeclaringClass())) {
|
||||
return null;
|
||||
}
|
||||
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
|
||||
return (function != null ? getParameterNames(function.getParameters()) : null);
|
||||
try {
|
||||
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
|
||||
return (function != null ? getParameterNames(function.getParameters()) : null);
|
||||
}
|
||||
catch (UnsupportedOperationException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -72,8 +77,13 @@ public class KotlinReflectionParameterNameDiscoverer implements ParameterNameDis
|
|||
if (!useKotlinSupport(ctor.getDeclaringClass())) {
|
||||
return null;
|
||||
}
|
||||
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(ctor);
|
||||
return (function != null ? getParameterNames(function.getParameters()) : null);
|
||||
try {
|
||||
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(ctor);
|
||||
return (function != null ? getParameterNames(function.getParameters()) : null);
|
||||
}
|
||||
catch (UnsupportedOperationException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
Loading…
Reference in New Issue