Skip to content
This repository has been archived by the owner on Feb 23, 2023. It is now read-only.

Kotlin: Native reflection config missing kotlin.internal.jdk8.JDK8PlatformImplementations #1646

Closed
Tonne-TM opened this issue Jun 17, 2022 · 3 comments
Labels
for: external-project For an external project and not something we can fix

Comments

@Tonne-TM
Copy link

My native compiled image throws the following exception when launching a coroutine:

2022-06-17 13:37:15.783 ERROR 34232 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Native reflection configuration for kotlin.internal.jdk8.JDK8PlatformImplementations.<init>() is missing.

Action:

Native configuration for a method accessed reflectively is likely missing.
You can try to configure native hints in order to specify it explicitly.
See https://docs.spring.io/spring-native/docs/current/reference/htmlsingle/#native-hints for more details.

Minimal project to reproduce:

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
...

@SpringBootApplication
class DemoApplication

fun main(args: Array<String>) {
	runApplication<DemoApplication>(*args)
}

@Component
class Starter : ApplicationRunner {

	private val logger = LoggerFactory.getLogger(javaClass)

	override fun run(args: ApplicationArguments?) = runBlocking<Unit> {
		launch(Dispatchers.Default) {
			logger.info("log smth out of coroutine")
		}
	}
}
  • Build using ./gradlew nativeCompile

-> When I remove launch(Dispatchers.Default) it is working fine in native image

Setup

  • GraalVM CE 22.1.0 (build 17.0.3+7-jvmci-22.1-b06)
  • Mac M1 (macOS 12.2.1)
@sdeleuze
Copy link
Contributor

Seems unrelated to Spring Native and we are unlikely adding entries for kotlin.internal.* classes (since they are internal), so I would advise to create a non Spring repro with native image and submit a Kotlin issue asking if this reflection invocation could be avoided.

@sdeleuze sdeleuze added for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 22, 2022
@Tonne-TM
Copy link
Author

The issue will be investigated under this already existing Kotlin ticket:
https://youtrack.jetbrains.com/issue/KT-51579

Short term solution (which I grabbed from the official Ktor GraalVM example), add the following reflection config under /src/main/resources/META-INF/native-image/reflect-config.json

[
  {
    "name": "kotlin.reflect.jvm.internal.ReflectionFactoryImpl",
    "allDeclaredConstructors":true
  },
  {
    "name": "kotlin.KotlinVersion",
    "allPublicMethods": true,
    "allDeclaredFields":true,
    "allDeclaredMethods":true,
    "allDeclaredConstructors":true
  },
  {
    "name": "kotlin.KotlinVersion[]"
  },
  {
    "name": "kotlin.KotlinVersion$Companion"
  },
  {
    "name": "kotlin.KotlinVersion$Companion[]"
  },
  {
    "name": "kotlin.internal.jdk8.JDK8PlatformImplementations",
    "allPublicMethods": true,
    "allDeclaredFields":true,
    "allDeclaredMethods":true,
    "allDeclaredConstructors":true
  }
]

@sdeleuze
Copy link
Contributor

Thanks for the update.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
for: external-project For an external project and not something we can fix
Development

No branches or pull requests

3 participants