Skip to content

Commit

Permalink
Defensively check MethodParameter.getMethod() in KotlinDelegate
Browse files Browse the repository at this point in the history
Closes gh-33609
  • Loading branch information
jhoeller committed Sep 30, 2024
1 parent e32a2f3 commit 95f1813
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

import jakarta.servlet.ServletException;
Expand Down Expand Up @@ -107,9 +106,9 @@ public final Object resolveArgument(MethodParameter parameter, @Nullable ModelAn

NamedValueInfo namedValueInfo = getNamedValueInfo(parameter);
MethodParameter nestedParameter = parameter.nestedIfOptional();
boolean hasDefaultValue = KotlinDetector.isKotlinReflectPresent()
&& KotlinDetector.isKotlinType(parameter.getDeclaringClass())
&& KotlinDelegate.hasDefaultValue(nestedParameter);
boolean hasDefaultValue = KotlinDetector.isKotlinReflectPresent() &&
KotlinDetector.isKotlinType(parameter.getDeclaringClass()) &&
KotlinDelegate.hasDefaultValue(nestedParameter);

Object resolvedName = resolveEmbeddedValuesAndExpressions(namedValueInfo.name);
if (resolvedName == null) {
Expand Down Expand Up @@ -336,6 +335,7 @@ public NamedValueInfo(String name, boolean required, @Nullable String defaultVal
}
}


/**
* Inner class to avoid a hard dependency on Kotlin at runtime.
*/
Expand All @@ -346,7 +346,10 @@ private static class KotlinDelegate {
* or an optional parameter (with a default value in the Kotlin declaration).
*/
public static boolean hasDefaultValue(MethodParameter parameter) {
Method method = Objects.requireNonNull(parameter.getMethod());
Method method = parameter.getMethod();
if (method == null) {
return false;
}
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
if (function != null) {
int index = 0;
Expand All @@ -359,4 +362,5 @@ public static boolean hasDefaultValue(MethodParameter parameter) {
return false;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

import kotlin.reflect.KFunction;
Expand Down Expand Up @@ -227,9 +226,9 @@ private Mono<Object> getDefaultValue(NamedValueInfo namedValueInfo, MethodParame

return Mono.fromSupplier(() -> {
Object value = null;
boolean hasDefaultValue = KotlinDetector.isKotlinReflectPresent()
&& KotlinDetector.isKotlinType(parameter.getDeclaringClass())
&& KotlinDelegate.hasDefaultValue(parameter);
boolean hasDefaultValue = KotlinDetector.isKotlinReflectPresent() &&
KotlinDetector.isKotlinType(parameter.getDeclaringClass()) &&
KotlinDelegate.hasDefaultValue(parameter);
if (namedValueInfo.defaultValue != null) {
value = resolveEmbeddedValuesAndExpressions(namedValueInfo.defaultValue);
}
Expand Down Expand Up @@ -328,6 +327,7 @@ public NamedValueInfo(String name, boolean required, @Nullable String defaultVal
}
}


/**
* Inner class to avoid a hard dependency on Kotlin at runtime.
*/
Expand All @@ -338,7 +338,10 @@ private static class KotlinDelegate {
* or an optional parameter (with a default value in the Kotlin declaration).
*/
public static boolean hasDefaultValue(MethodParameter parameter) {
Method method = Objects.requireNonNull(parameter.getMethod());
Method method = parameter.getMethod();
if (method == null) {
return false;
}
KFunction<?> function = ReflectJvmMapping.getKotlinFunction(method);
if (function != null) {
int index = 0;
Expand Down

0 comments on commit 95f1813

Please sign in to comment.