micronaut-projects / micronaut-kotlin

Additional projects that improve the Micronaut experience with Kotlin
Apache License 2.0
89 stars 17 forks source link

Trying to build a native-image in 2.0.3 throws an error: Fatal error:java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Class com.typesafe.config.Config cannot be instantiated reflectively. It must be a non-abstract instance type. #173

Closed shahmirn closed 4 years ago

shahmirn commented 4 years ago

Upgrading a project from 2.0.1 to 2.0.3 causes native image compilation to stop working. It throws the following error:

Fatal error:java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Class com.typesafe.config.Config cannot be instantiated reflectively. It must be a non-abstract instance type. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:593) at java.util.concurrent.ForkJoinTask.get(ForkJoinTask.java:1005) at com.oracle.svm.hosted.NativeImageGenerator.run(NativeImageGenerator.java:480) at com.oracle.svm.hosted.NativeImageGeneratorRunner.buildImage(NativeImageGeneratorRunner.java:349) at com.oracle.svm.hosted.NativeImageGeneratorRunner.build(NativeImageGeneratorRunner.java:508) at com.oracle.svm.hosted.NativeImageGeneratorRunner.main(NativeImageGeneratorRunner.java:114) Caused by: java.lang.IllegalArgumentException: Class com.typesafe.config.Config cannot be instantiated reflectively. It must be a non-abstract instance type. at org.graalvm.nativeimage.hosted.RuntimeReflection.registerForReflectiveInstantiation(RuntimeReflection.java:120) at io.micronaut.context.env.hocon.nativeimage.HoconFeature.registerClassForRuntimeReflection(HoconFeature.kt:44) at io.micronaut.context.env.hocon.nativeimage.HoconFeature.beforeAnalysis(HoconFeature.kt:37) at com.oracle.svm.hosted.NativeImageGenerator.lambda$runPointsToAnalysis$7(NativeImageGenerator.java:693) at com.oracle.svm.hosted.FeatureHandler.forEachFeature(FeatureHandler.java:70) at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:693) at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:555) at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:468) at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386) at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:163) Error: Image build request failed with exit status 1

NOTE: If you are unsure about something and the issue is more of a question a better place to ask questions is on Stack Overflow (https://stackoverflow.com/tags/micronaut) or Gitter (https://gitter.im/micronautfw/). DO NOT use the issue tracker to ask questions.

Task List

Steps to Reproduce

  1. Go to https://micronaut.io/ and click generate project.
  2. Select Java 8, Kotlin, and KoTest
  3. Click on Features, and select management, data-jpa, file-watch, graalvm, kotlin-extension-functions, mysql, and logback
  4. Generate project
  5. ./gradlew assemble
  6. ./docker-build.sh

Expected Behaviour

Native image should be created successfully

Actual Behaviour

IllegalArgumentException is thrown.

Environment Information

Example Application

https://github.com/shahmirn/micronaut-bugs/tree/micronaut-2-0-3-native-image-bug

graemerocher commented 4 years ago

Bug seems to be here https://github.com/micronaut-projects/micronaut-kotlin/blob/27b987a02928ba245d68ec91dc79869d8c452d00/kotlin-runtime/src/main/kotlin/io/micronaut/context/env/hocon/nativeimage/HoconFeature.kt#L36

Probably Config was a class but it is not an interface so this line needs removing.

ilopmar commented 4 years ago

Fixed by #174