From 15232bf4d40e64df242adf2f8c263e6bb2bac6bc Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Thu, 14 Nov 2024 09:07:17 +0200 Subject: [PATCH] Register Kotlin's empty list and map for reflection Fixes: #44472 --- .../quarkus/kotlin/deployment/KotlinProcessor.java | 2 ++ .../kotlin/io/quarkus/it/kotser/GreetingResource.kt | 12 ++++++++++++ .../test/kotlin/io/quarkus/it/kotser/ResourceTest.kt | 10 ++++++++++ 3 files changed, 24 insertions(+) diff --git a/extensions/kotlin/deployment/src/main/java/io/quarkus/kotlin/deployment/KotlinProcessor.java b/extensions/kotlin/deployment/src/main/java/io/quarkus/kotlin/deployment/KotlinProcessor.java index 340f4de9888ac..aff88dfbd80b2 100644 --- a/extensions/kotlin/deployment/src/main/java/io/quarkus/kotlin/deployment/KotlinProcessor.java +++ b/extensions/kotlin/deployment/src/main/java/io/quarkus/kotlin/deployment/KotlinProcessor.java @@ -61,6 +61,8 @@ void registerKotlinReflection(final BuildProducer refl .build()); reflectiveClass.produce(ReflectiveClassBuildItem.builder("kotlin.KotlinVersion$Companion[]").constructors(false) .build()); + reflectiveClass.produce( + ReflectiveClassBuildItem.builder("kotlin.collections.EmptyList", "kotlin.collections.EmptyMap").build()); nativeResourcePatterns.produce(builder().includePatterns( "META-INF/.*.kotlin_module$", diff --git a/integration-tests/kotlin-serialization/src/main/kotlin/io/quarkus/it/kotser/GreetingResource.kt b/integration-tests/kotlin-serialization/src/main/kotlin/io/quarkus/it/kotser/GreetingResource.kt index f03c9a4729413..a1d0804d563c0 100644 --- a/integration-tests/kotlin-serialization/src/main/kotlin/io/quarkus/it/kotser/GreetingResource.kt +++ b/integration-tests/kotlin-serialization/src/main/kotlin/io/quarkus/it/kotser/GreetingResource.kt @@ -73,5 +73,17 @@ class GreetingResource { return Response.ok().entity(javaMethod.invoke(this)).build() } + @GET + @Path("emptyList") + fun emptyList(): List { + return emptyList() + } + + @GET + @Path("emptyMap") + fun emptyMap(): Map { + return emptyMap() + } + fun reflect() = "hello, world" } diff --git a/integration-tests/kotlin-serialization/src/test/kotlin/io/quarkus/it/kotser/ResourceTest.kt b/integration-tests/kotlin-serialization/src/test/kotlin/io/quarkus/it/kotser/ResourceTest.kt index df95d3b5ea7e3..35d43c86e164f 100644 --- a/integration-tests/kotlin-serialization/src/test/kotlin/io/quarkus/it/kotser/ResourceTest.kt +++ b/integration-tests/kotlin-serialization/src/test/kotlin/io/quarkus/it/kotser/ResourceTest.kt @@ -124,4 +124,14 @@ open class ResourceTest { body(CoreMatchers.equalTo("hello, world")) } } + + @Test + fun testEmptyList() { + When { get("/emptyList") } Then { statusCode(200) } + } + + @Test + fun testEmptyMap() { + When { get("/emptyList") } Then { statusCode(200) } + } }