Refine KotlinDetector usages and implementation

This commit refines KotlinDetector usages and implementation in order
to remove preliminary KotlinDetector#isKotlinReflectPresent invocations
and to ensure that KotlinDetector methods are implemented safely and
efficiently for such use case.

Closes gh-34275
This commit is contained in:
Sébastien Deleuze
2025-01-17 16:21:50 +01:00
parent ffd7b93dde
commit 1763334180
15 changed files with 56 additions and 66 deletions

View File

@@ -868,8 +868,7 @@ public class Jackson2ObjectMapperBuilder {
// jackson-datatype-jsr310 not available
}
// Kotlin present?
if (KotlinDetector.isKotlinPresent()) {
if (KotlinDetector.isKotlinReflectPresent()) {
try {
Class<? extends Module> kotlinModuleClass = (Class<? extends Module>)
ClassUtils.forName("com.fasterxml.jackson.module.kotlin.KotlinModule", this.moduleClassLoader);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -103,8 +103,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
NamedValueInfo namedValueInfo = getNamedValueInfo(parameter);
MethodParameter nestedParameter = parameter.nestedIfOptional();
boolean hasDefaultValue = KotlinDetector.isKotlinReflectPresent() &&
KotlinDetector.isKotlinType(parameter.getDeclaringClass()) &&
boolean hasDefaultValue = KotlinDetector.isKotlinType(parameter.getDeclaringClass()) &&
KotlinDelegate.hasDefaultValue(nestedParameter);
Object resolvedName = resolveEmbeddedValuesAndExpressions(namedValueInfo.name);
@@ -276,7 +275,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle
WebDataBinder binder = binderFactory.createBinder(webRequest, null, namedValueInfo.name);
Class<?> parameterType = parameter.getParameterType();
if (KotlinDetector.isKotlinPresent() && KotlinDetector.isInlineClass(parameterType)) {
if (KotlinDetector.isInlineClass(parameterType)) {
Constructor<?> ctor = BeanUtils.findPrimaryConstructor(parameterType);
if (ctor != null) {
parameterType = ctor.getParameterTypes()[0];

View File

@@ -242,13 +242,11 @@ public class InvocableHandlerMethod extends HandlerMethod {
protected @Nullable Object doInvoke(@Nullable Object... args) throws Exception {
Method method = getBridgedMethod();
try {
if (KotlinDetector.isKotlinReflectPresent()) {
if (KotlinDetector.isKotlinType(method.getDeclaringClass())) {
if (KotlinDetector.isSuspendingFunction(method)) {
return invokeSuspendingFunction(method, getBean(), args);
}
else if (KotlinDetector.isKotlinType(method.getDeclaringClass())) {
return KotlinDelegate.invokeFunction(method, getBean(), args);
}
return KotlinDelegate.invokeFunction(method, getBean(), args);
}
return method.invoke(getBean(), args);
}