From a9f511c17014a9145aec899ab5e9b6f8ef228f8e Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 7 Oct 2022 12:18:32 -0400 Subject: [PATCH] Remove reflection handling for kotlin.Unit class There is just enough to check the value type name against "kotlin.Unit" literal. This way we don't need extra reflection bits to be exposed into a native image --- .../integration/aot/CoreRuntimeHints.java | 3 +-- .../integration/util/ClassUtils.java | 19 +------------------ 2 files changed, 2 insertions(+), 20 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/aot/CoreRuntimeHints.java b/spring-integration-core/src/main/java/org/springframework/integration/aot/CoreRuntimeHints.java index 2b3bc6750b..5f0face84b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/aot/CoreRuntimeHints.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/aot/CoreRuntimeHints.java @@ -100,8 +100,7 @@ class CoreRuntimeHints implements RuntimeHintsRegistrar { Stream.of( "kotlin.jvm.functions.Function0", - "kotlin.jvm.functions.Function1", - "kotlin.Unit") + "kotlin.jvm.functions.Function1") .forEach(type -> reflectionHints.registerTypeIfPresent(classLoader, type, MemberCategory.INVOKE_PUBLIC_METHODS)); diff --git a/spring-integration-core/src/main/java/org/springframework/integration/util/ClassUtils.java b/spring-integration-core/src/main/java/org/springframework/integration/util/ClassUtils.java index dfe48ab894..c42bf1f904 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/util/ClassUtils.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/util/ClassUtils.java @@ -84,11 +84,6 @@ public abstract class ClassUtils { */ public static final Class KOTLIN_FUNCTION_1_CLASS; - /** - * The {@code kotlin.Unit} class object. - */ - public static final Class KOTLIN_UNIT_CLASS; - static { PRIMITIVE_WRAPPER_TYPE_MAP.put(Boolean.class, boolean.class); PRIMITIVE_WRAPPER_TYPE_MAP.put(Byte.class, byte.class); @@ -166,23 +161,11 @@ public abstract class ClassUtils { finally { KOTLIN_FUNCTION_1_CLASS = kotlinClass; } - - kotlinClass = null; - try { - kotlinClass = org.springframework.util.ClassUtils.forName("kotlin.Unit", defaultClassLoader); - } - catch (ClassNotFoundException e) { - //Ignore: assume no Kotlin in classpath - } - finally { - KOTLIN_UNIT_CLASS = kotlinClass; - } } else { KOTLIN_FUNCTION_0_CLASS = null; KOTLIN_FUNCTION_0_INVOKE_METHOD = null; KOTLIN_FUNCTION_1_CLASS = null; - KOTLIN_UNIT_CLASS = null; } } @@ -278,7 +261,7 @@ public abstract class ClassUtils { * @since 5.3.2 */ public static boolean isKotlinUnit(Class aClass) { - return KOTLIN_UNIT_CLASS != null && KOTLIN_UNIT_CLASS.isAssignableFrom(aClass); + return "kotlin.Unit".equals(aClass.getName()); } }